473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

dictionary update

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
Aug 15 '06 #1
2 1515
Chris <cf*****@bigpond.net.auwrote:
>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).
I think what you want is:

for i in list_of_is:
getattr(self, i).update(locals()[i])

assuming list_of_is is a list of names not a list of the local
dicts (ie ["xds", ...] not [xds, ...]).

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Aug 15 '06 #2
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

Aug 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Elbert Lev | last post by:
Hi! Here is the problem: I have a dictionary. Keys are strings. How to make dictionary lookup case insensitive? In other words: If dict = {'First":"Bob", "Last":"Tom"}, dict should return...
4
by: brianobush | last post by:
# # My problem is that I want to create a # class, but the variables aren't known # all at once. So, I use a dictionary to # store the values in temporarily. # Then when I have a complete set, I...
8
by: Almad | last post by:
Hello, I discovered this behaviour in dictionary which I find confusing. In SneakyLang, I've tried to extend dictionary so it visits another class after something is added: class...
1
by: Martin P. Hellwig | last post by:
Hi all, I'm thinking to speed up a process, I like to use multiple threads to get data fractions from multiple servers and place those data fragments into a local dictionary for further...
2
by: joe.kimbler | last post by:
What is the best way to handle updates in databases with each release of a software package? I used to work on an accounting package in FoxPro that had a "Data Dictionary" and as your code...
0
by: xpding | last post by:
Hello, I have a class MyEmbededList contains a generic dictionary, the value field is actually the MyEmbededList type as well. There is another class need to access and manipulate a list of...
5
by: Bill Jackson | last post by:
What is the benefit of clearing a dictionary, when you can just reassign it as empty? Similarly, suppose I generate a new dictionary b, and need to have it accessible from a. What is the best...
4
by: =?Utf-8?B?YW1pcg==?= | last post by:
do i have to remove the pair and then reinsert it or can i just update the value of the dictionary
3
by: mk | last post by:
Hello everyone, I'm storing functions in a dictionary (this is basically for cooking up my own fancy schmancy callback scheme, mainly for learning purpose): .... return "f2 " + arg .......
7
by: mmm | last post by:
I found code to undo a dictionary association. def undict(dd, name_space=globals()): for key, value in dd.items(): exec "%s = %s" % (key, repr(value)) in name_space So if i run I get
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.