String as a Variable?

Daehyok Shin DSHIN at nc.rr.com
Fri Feb 2 10:31:03 EST 2001


Use __dict__.
For example, in a class,

str='ip_address_serial'
self.__dict__[str]=str
print self.ip_address_serial

<binnc at my-deja.com> wrote in message news:95eih7$si$1 at nnrp1.deja.com...
> Another newbie question...
>
> Is there a way to have a string represent a variable.
>
> For eaxample, I have a the following:
>
> <snip>
>
> serial_number = '3'
> print 'ip_address_serial_' + serial_number
> ip_address_serial_3
>
> Now I want to use the string ip_address_serial_3 to pull
> the value assigned to the variable of the same name.
>
> How can I represent the string as a variable?
>
> Thanks in advance!
>
>
> Sent via Deja.com
> http://www.deja.com/





More information about the Python-list mailing list