student question

Corey Richardson kb1pkl at aim.com
Fri Jan 7 21:47:05 EST 2011


On 01/07/2011 09:42 PM, John wrote:
>>>> q_file = open(questions_location) #opens the document successfully
>>>> for line in q_file:
> 		print line
> 
> # prints document successfully
>>>> line
> # prints last line of document
>>>> for line in q_file:
> 		print line # prints nothing
> 
> ...why does it print nothing?

IIRC, iterating through the lines in a file moves the cursor (is that
the correct term?) to the end of the file. After the first one, use
q_file.seek(0) to go back to the start. I think.

~Corey Richardson



More information about the Python-list mailing list