"Karim Liateni" <karim.liat...@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/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to