x = eval(repr(sys.stdout)) ?

rtm mclay at jedrik.ae.utexas.edu
Tue Aug 6 22:23:30 CEST 2002

I would like to turn the representation of a stream back into a

If I do this under python 2.2.1 running under Linux I get:

   >>> import sys
   >>> x = eval(repr(sys.stdout))
   Traceback (most recent call last):
     File "<stdin>", line 1, in ?
     File "<string>", line 1
       <open file '<stdout>', mode 'w' at 0x8101a40>
   SyntaxError: invalid syntax

So is this possible?

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.

Only I don't want to have to remember that when later comes around
that it was sys.stdout but some stream.

So the question is:  Is there a way to save a "pointer" to a variable in
python so that it can be set latter?

In C++ I might do:

#include <iostream>
using namespace std;

int main()
  int foo = 1;
  int *bar = &foo;

  *bar = 2;

  cout << "foo: " << foo << endl;

and foo is now 2.  Is there something that can do this in python?

More information about the Python-list mailing list