variable variables?

Chris Lawrence quango at watervalley.net
Wed Aug 9 20:45:34 EDT 2000


On Thu, 10 Aug 2000 00:38:20 GMT, Matthew R. MacIntyre <matt at matty.dyndns.org> wrote:
> More specifically, i'm trying to set instance variables in a class using
> an argument containing a dictionary in the constructor .... something like
> this:
> 
> class TestClass:
> 	def __init__(self,dict):
>            for x in dict.keys()
>              self._{x} = dict[x]

for x in dict.keys():
  self.__dict__[x] == dict[x]

or (more elegantly):

self.__dict__.update(dict)

(The latter may be a 1.6ism; I don't remember)


Chris
-- 
=============================================================================
|        Chris Lawrence         |     Get rid of Roger Wicker this year!    |
|   <quango at watervalley.net>    |      http://www.lordsutch.com/ms-one/     |
|                               |                                           |
|     Open Directory Editor     |    Join the party that opposed the CDA    |
|       http://dmoz.org/        |             http://www.lp.org/            |
=============================================================================



More information about the Python-list mailing list