Why can't I restore my redirected stdout?
Raymond Ng Tong Leng
think2 at pd.jaring.my
Thu Jun 8 13:52:52 EDT 2000
I am trying to implement a verbose and quiet mode in my Python script. So I
wrote the following class:
class Quiet:
def write(self, data):
pass
Then I set sys.stdout to Quiet by:
>>> sys.stdout = Quiet()
>>> print 'hello'
>>>
'hello' doesn't come out which is what I want. But, when I tried to restore
sys.stdout's original settings:
>>> sys.stdout = sys.__stdout__
>>> print 'hello'
>>>
'hello' is not printed either! How do you restore sys.stdout to its original
settings? Also, I was wondering, are there other ways to suppress
sys.stdout? I'm just curious whether I could suppress sys.stdout without
redirecting to a class. It seems to me that I should be able to redirect
sys.stdout to a null device or something. Thanks!
More information about the Python-list
mailing list