Python: How do I create a reference to a reference?

Posted by KCArpe on Stack Overflow See other posts from Stack Overflow or by KCArpe
Published on 2010-05-17T02:14:40Z Indexed on 2010/05/17 2:20 UTC
Read the original article Hit count: 320

Filed under:
|
|

Hi,

I am traditionally a Perl and C++ programmer, so apologies in advance if I am misunderstanding something trivial about Python!

I would like to create a reference to a reference. Huh? Ok. All objects in Python are actually references to the real object. So, how do I create a reference to this reference?

Why do I need/want this? I am overriding sys.stdout and sys.stderr to create a logging library. I would like a (second-level) reference to sys.stdout.

If I could create a reference to a reference, then I could create a generic logger class where the init function receives a reference to a file handle reference that will be overrided, e.g., sys.stdout or sys.stderr. Currently, I must hard-code both values.

Cheers, Kevin

© Stack Overflow or respective owner

Related posts about python

Related posts about reference