finished #stdio and #redirect sections, added xrefs in appendix B, added new example file

This commit is contained in:
Mark Pilgrim
2009-07-19 12:01:22 -04:00
parent 7e21f9ce71
commit 97d84abb5e
3 changed files with 116 additions and 96 deletions
+17
View File
@@ -0,0 +1,17 @@
import sys
class RedirectStdoutTo:
def __init__(self, out_new):
self.out_new = out_new
def __enter__(self):
self.out_old = sys.stdout
sys.stdout = self.out_new
def __exit__(self, *args):
sys.stdout = self.out_old
print('A')
with open('out.log', mode='w', encoding='utf-8') as a_file, RedirectStdoutTo(a_file):
print('B')
print('C')