From: evan at tokenexchange.com (Evan Simpson)
Date: Thu, 22 Apr 1999 12:52:51 -0500
Subject: Pointers to variables
References: <19990422121403.A279051@vislab.epa.gov>
Message-ID: <8lJT2.17$eD1.14436@news.corridex.com>
X-UID: 1602                                                  

Randall Hopper wrote in message <19990422121403.A279051 at vislab.epa.gov>...
[snip]
> How can I cause a reference to the variables to be stored in the tuples
instead of their values?

You can't, or at least not directly.  What you *can* do, in the case you
provided, is something like this:

for ( attrname, k ) in [( 'min', 'min_units' ), ( 'max', 'max_units' )]:
    if cnf.has_key( k ):
        setattr(self, attrname, cnf[ str ])
        del cnf[ str ]

Python simply doesn't *have* variables in the sense you're thinking of, with
the exception of function-local variables.  Instead it has namespaces, such
as modules, classes, and instances.  These can be usefully be thought of as
dictionaries with efficient string-only keys, and can be manipulated as such
using getattr, setattr, delattr, etc.

Function-local-variables-are-a-whole-nother-alien-world-ly yrs,
Evan Simpson






