dictionary update

Steve Holden steve at holdenweb.com
Tue Aug 15 09:34:39 EDT 2006


Chris wrote:
> I have a instance attribute self.xds and a local variable xds in the 
> instance . Both are dictionaries. I understand that I can update 
> self.xds with xds as follows: self.xds.update(xds)
> 
> However I have many instance attributes, self.i, and local variables i.
> I'd like to be able to do this:
> 
> for i in list_of_i's:
>      self.i.update(i)
> 
> How can this be done (I'm assuming it can be).
> 
> thx Chris

Well, I'm note sure you have explained the problem fully, but if what 
you mean is that you want to update an instance's variables from a 
dictionary this can be achieved with

   self.__dict__.update(xds)

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list