[Tutor] Any Tutor there ? Removing redundant parameters in a models file having include files.

Alan Gauld alan.gauld at btinternet.com
Mon Mar 1 02:04:04 CET 2010


"Karim Liateni" <karim.liateni at free.fr> wrote

> def getLines(file):
>   try: lines = open(filename).readlines() ; return lines
>   except IOError: #handle error
>
>
> but in the second 'lines = open(filename).readlines()'
> I don't hold indirectly a reference to the file? Please, could you 
> explain more this point?

Sure, the lines variable holds a reference to the list returned by 
readlines.
There is no variable referring to the file object so immediately after
readlines completes the file will be ready to be closed (at least in
CPython as already pointed out by Lie)

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list