pythonreference.com
search statements, functions, methods, exceptions*
show categories
'for' with a file
iterate over each string line in a file
fh = open('thisfile.txt')
for myline in fh:
print(myline)
for str in file: print str
|
as Python iterates over each line in the file, it assigns the line to the
loop variable (in the example, 'myline') as a string, then executes the block.
The assignment and block execution happen once for each line in the file