x = eval(repr(sys.stdout)) ?
Chris Liechti
cliechti at gmx.net
Wed Aug 7 15:19:49 EDT 2002
mclay <mclay at cfdlab.ae.utexas.edu> wrote in
news:3D503F3F.6683E676 at cfdlab.ae.utexas.edu:
> I would like to turn the representation of a stream back into a
> stream.
> >>> x = eval(repr(sys.stdout))
no need for repr here...
just save the file object (the reference to it) in an other variable:
saveout = sys.stdout
sys.stdout = open("log.txt","w")
at the end:
sys.stdout = saveout
> So the question is: Is there a way to save a "pointer" to a variable in
> python so that it can be set latter?
all objects in python are referenced. you can easly have two names
(variables) that referece the same object.
>>> a = []
>>> b = a
>>> b.append("hello")
>>> print a
the trick is that you need a muatble object. so you cannot change anumber
directly, but you can put in a list and change the element in the list.
>>> a = [1]
>>> b = a
>>> b[0] = 2
>>> print a
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list