diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-03 16:42:25 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-03 22:09:05 +0300 |
commit | c61ce965909d1005e8ea45f40320aa5545cad522 (patch) | |
tree | ea1ee7d9771360ac78dff91c4ecb45d32cf0b010 /tests | |
parent | 98a627dc03bc02e1b827ead8cc71b02259731551 (diff) | |
download | micropython-c61ce965909d1005e8ea45f40320aa5545cad522.tar.gz micropython-c61ce965909d1005e8ea45f40320aa5545cad522.zip |
unix file: Implement context manager protocol (for "with" statement).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/io/file-with.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/io/file-with.py b/tests/io/file-with.py new file mode 100644 index 0000000000..2350721641 --- /dev/null +++ b/tests/io/file-with.py @@ -0,0 +1,12 @@ +f = open("io/data/file1") + +with f as f2: + print(f2.read()) + +# File should be closed +try: + f.read() +except: + # Note: CPython and us throw different exception trying to read from + # close file. + print("can't read file after with") |