commit | ac625351643d5732bcaa77844ef1506bf5c978ab | [log] [tgz] |
---|---|---|
author | Antoine Pitrou <solipsis@pitrou.net> | Wed Dec 09 00:01:27 2009 +0000 |
committer | Antoine Pitrou <solipsis@pitrou.net> | Wed Dec 09 00:01:27 2009 +0000 |
tree | 620f07c70671ea90bd42d61ae51d0fcf19a93f34 | |
parent | 9b14f6044ce261ed2c9154d1c8466ff50e697c2e [diff] [blame] |
Issue #7461: objects returned by os.popen() should support the context manager protocol
diff --git a/Lib/os.py b/Lib/os.py index ec5d280..2a9937f 100644 --- a/Lib/os.py +++ b/Lib/os.py
@@ -650,6 +650,10 @@ return returncode else: return returncode << 8 # Shift left to match old behavior + def __enter__(self): + return self + def __exit__(self, *args): + self.close() def __getattr__(self, name): return getattr(self._stream, name) def __iter__(self):