In python c = pickle.load(open(fileName, 'r')) does this close the file? -
i tried google cannot find answer.
if
c = pickle.load(open(filename, 'r'))
will file automatically closed after operation?
no, can adapt close file:
# file not yet opened open(filename, 'r') f: # file opened c = pickle.load(f) # file opened # file closed
what with
statement does, (among other things) calling __exit__()
method of object listed in with
statement (in case: opened file), in case closes file.
regarding opened file's __exit__()
method:
>>> f = open('deleteme.txt', 'w') >>> help(f.__exit__) on built-in function __exit__: __exit__(...) __exit__(*excinfo) -> none. closes file.
Comments
Post a Comment