pointer and python
Mohsen Pahlevanzadeh
mohsen at pahlevanzadeh.org
Thu Oct 17 23:13:12 EDT 2013
On Fri, 2013-10-18 at 00:54 +0100, MRAB wrote:
> 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?
>
At first i store them in a dict:
###########################################33
for row in xrange(len(uniqueFields) ):
111111111111instance = QtGui.QCheckBox(uniqueFields[row])
111111111111projectsFindInstance.projectsInstance.addOnFieldsInstance.update({uniqueFields[row]:instance})
111111111111projectsFindInstance.tableWidget.setCellWidget(row,0,instance) 111111111111projectsFindInstance.tableWidget.setRowCount(projectsFindInstance.tableWidget.rowCount()+1)
###########################3
above 1 digits are intending...!
At first i store them as QCheckBox object in a dict, then i need to
create connect function according them:
################################################################
for key, val in
self.projectsInstance.addOnFieldsInstance.items():
setattr(self,"%s" % val,val)
instance = getattr(self,"%s" % val)
QtCore.QObject.connect(instance ,
QtCore.SIGNAL(_fromUtf8("stateChanged (int)")), lambda:
self.projectsInstance.setFilterDict_Find("TWCH",self,instance,instance.checkState()))
##########################
setttr and getattr and connect are in for loop.
But i have serious question:
how i can retrive content of a varibale such as C pointer:
p = *x ;
setattr(self,"%s" %val , *val) ==> i need to paste content of content of
val variable.
--mohsen
More information about the Python-list
mailing list