Does filehandle get closed automatically in Python after it goes out of scope?

Posted by bodacydo on Stack Overflow See other posts from Stack Overflow or by bodacydo
Published on 2010-03-08T20:18:51Z Indexed on 2010/03/08 20:21 UTC
Read the original article Hit count: 402

Filed under:
|
|

If I do the following, does filehandle get closed automatically as it goes out of scope in Python:

def read_contents(file_path):
  return file(file_path).read()

If it doesn't, how can I write this function to close the scope automatically?

© Stack Overflow or respective owner

Related posts about python

Related posts about file