pointer and python
MRAB
python at mrabarnett.plus.com
Thu Oct 17 19:54:31 EDT 2013
On 18/10/2013 00:17, Mohsen Pahlevanzadeh wrote:
> Dear all,
>
> Suppose I have the following code:
> ##########################################3
> mydic = dict()
> 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.
> #####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 ?
>
Why are you using attributes anyway? Why not just store them in a dict?
More information about the Python-list
mailing list