From: tismer at appliedbiometrics.com (Christian Tismer) Date: Thu, 22 Apr 1999 18:04:36 GMT Subject: Pointers to variables References: <19990422121403.A279051@vislab.epa.gov> Message-ID: <371F64B4.8DF3FF24@appliedbiometrics.com> Content-Length: 1404 X-UID: 457 Randall Hopper wrote: > > This doesn't work: > > for ( var, str ) in [( self.min, 'min_units' ), > ( self.max, 'max_units' )]: > if cnf.has_key( str ): > var = cnf[ str ] > del cnf[ str ] > > It doesn't assign values to self.min, self.max (both integers). The values > of these variables are inserted into the tuples and not references to the > variables themselves, which is the problem. > > How can I cause a reference to the variables to be stored in the tuples > instead of their values? There is simply no direct way to use references. You need to use an object which itself has a reference. One way to achive the wanted effect is to use setattr, while paying some speed penalty, of course: for ( var, str ) in [( 'min', 'min_units' ), ( 'max', 'max_units' )]: if cnf.has_key( str ): setattr(self, var, cnf[ str ]) del cnf[ str ] ciao - chris -- Christian Tismer :^) Applied Biometrics GmbH : Have a break! Take a ride on Python's Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net 10553 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home