So can I ask what happens internally in python when you create open a file
object in a loop without assigning that file object to a variable?

E.g.:

for line in open(file.py):
   print line

In the above, is pythonimplicitly creating a reference to a file object and
using that in the for loop? Or is something else going on under the hood?
Either way, I figured that if you don't assign the file object to a
variable, then the file object is trashed by python's garbage collection
once the loop reaches end-of-file.

Is the above a correct understanding?
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to