student question

J

John

q_file = open(questions_location) #opens the document successfully print line

# prints document successfully print line # prints nothing

....why does it print nothing?
 
C

Corey Richardson

print line

# prints document successfully
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
 
J

John

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

fantastic. thanks, corey!
 
P

Peter Pearson

print line

# prints document successfully
print line # prints nothing

...why does it print nothing?

open(filename) returns an iterator, not a list. Once you
have exhausted the iterator, it stays exhausted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top