[Tutor] does id function return location of reference or the referenced object?

Serdar Tumgoren zstumgoren at gmail.com
Fri Mar 6 18:09:03 CET 2009


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090306/73971580/attachment.htm>


More information about the Tutor mailing list