Skip to content

Instantly share code, notes, and snippets.

@mwhooker
Last active December 18, 2015 13:59
Show Gist options
  • Save mwhooker/5793945 to your computer and use it in GitHub Desktop.
Save mwhooker/5793945 to your computer and use it in GitHub Desktop.
>>> with open('test', 'w') as a:
... with open('test', 'w') as b:
... a.write('a')
... b.write('b')
...
>>>
[1] + 42274 suspended python
[mwhooker@Wolfe:~/test]$ cat test
a
@wolever
Copy link

wolever commented Jun 17, 2013

with open("test", "w") as f:
  for x in range(10):
      f.write("%s\n" %(x, ))
      if x > 6:
          raise Exception()

The file test will be left half-finished… Which is a problem if, somewhere, you make the assumption that the file is complete. https://github.com/shazow/unstdlib.py/pull/15/files#L2R9 ensures that either the file is completely written, or completely not written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment