Skip to content

Instantly share code, notes, and snippets.

@binki
Created October 23, 2015 17:11
Show Gist options
  • Save binki/61d739ecd2b158049f62 to your computer and use it in GitHub Desktop.
Save binki/61d739ecd2b158049f62 to your computer and use it in GitHub Desktop.
no need for closing(open()) for with
>>> f = open('c:\\users\\ohnob\\appdata\\local\\temp\\f.txt', 'w')
>>> with f as fi:
... fi.write('hi')
...
2
>>> f.write('there')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment