use 'with' to redirect stdout

Neal Becker ndbecker2 at gmail.com
Mon Feb 11 18:41:28 EST 2008


Thanks!  I understand this better now.  This is really an example of a more
general pattern:

@contextmanager
def rebind_attr(object_, attr, value):
    orig = getattr(object_, attr)
    setattr(object_, attr, value)
    yield
    setattr(object_, attr_, orig)





More information about the Python-list mailing list