From c61ce965909d1005e8ea45f40320aa5545cad522 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 3 Apr 2014 16:42:25 +0300 Subject: unix file: Implement context manager protocol (for "with" statement). --- tests/io/file-with.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/io/file-with.py (limited to 'tests/io/file-with.py') diff --git a/tests/io/file-with.py b/tests/io/file-with.py new file mode 100644 index 000000000..235072164 --- /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") -- cgit v1.2.3