top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

pointer and python

+1 vote
327 views

Suppose I have the following code:

##########################################3
mydict = dict()
mydict.update({'string':QtGui.QCheckBox()}) ## suppose this dic has many
value with some string and QCheckBox Object

#####Then i have itreate it :

for key, val in mydict.items():
 setattr(self,"%s" % val,XXX) ###===> this line is the given line
 getattr(self,"%s" % val)

############################################33

According to the above code, I fetch a set of object from dict and set them as attribute, But question is , val has value and it's important, and I can't replace any other value with it, What I replace with XXX in setattr ?

posted Oct 17, 2013 by Jagan Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
mydict.update({'string':QtGui.QCheckBox()}) ## suppose this dic has many
value with some string and QCheckBox Object

If you do this, you're giving them all the same key 'string', so only the last will be remembered.

According to the above code, i fetch a set of object from dict and set them as attribute, But question is , val has value and it's important, and i can't replace any other value with it, What i replace with XXX in setattr ?

Why are you using attributes anyway? Why not just store them in a dict?

answer Oct 18, 2013 by Dewang Chaudhary
...