x = eval(repr(sys.stdout)) ?
Gerson Kurz
moc.q-dnan-p at p-nand-q.com
Wed Aug 7 06:40:35 EDT 2002
On Wed, 07 Aug 2002 10:23:41 GMT, Robert McLay
<mclay at cfdlab.ae.utexas.edu> wrote:
>What am I really trying to do here? Well I want to redirect
>sys.stdout to be something else and the reset it back later.
like this? :
#!/usr/bin/python
import sys
class devnullout:
def write(self, msg):
# rocket-science: emulate a /dev/null device
pass
old_stdout = sys.stdout
sys.stdout = devnullout()
# TODO: add stuff that you won't see on sys.stdout
print "you don't see me"
# restore old stdout
sys.stdout = old_stdout
print "now you see me again"
>Only I don't want to have to remember that when later comes around
>that it was sys.stdout but some stream.
I don't get that.
>So the question is: Is there a way to save a "pointer" to a variable in
>python so that it can be set latter?
What does the one task - redirecting sys.stdout - have to do with
saving a pointer to a variable?
More information about the Python-list
mailing list