functools and objective usage

Mohsen Pahlevanzadeh mohsen at pahlevanzadeh.org
Wed Oct 23 12:48:47 EDT 2013


Dear all,

I have the following code in each steps of loop:
####################################################
            obj = partial(self.myinstance.myfunc)
            obj.func = self.myinstance.myfunc
            obj.arg = ["TWCH",self,key,val.checkState(),val]
            obj.keywords = self.myinstance
########################################################
But i get the following traceback:
############################################
Traceback (most recent call last):
  File "./main.py", line 117, in <module>
    main()
  File "./main.py", line 104, in main
    x.showFindProjects()
  File "/home/mohsen/codes/amlak/amlak/src/UIInterface.py", line 101, in
showFindProjects
    self.uiProjectsFind.setupUi(self.projectsFind)
  File "/home/mohsen/codes/amlak/amlak/src/projectsFind.py", line 288,
in setupUi
    obj.func = self.myinstance.myfunc
TypeError: readonly attribute
###############################################################
Before any help, Thank you...

Yours,
Mohsen

On Wed, 2013-10-23 at 00:56 +0100, MRAB wrote:
> On 22/10/2013 23:13, Ben Finney wrote:
> > Mohsen Pahlevanzadeh <mohsen at pahlevanzadeh.org> writes:
> >
> >> Suppose i have function name, 3 arguments for it, and object of its
> >> caller such as self.blahbalah
> >
> > This doesn't make much sense to me. I think you mean: You have an
> > object, ‘self.blahblah’, which has a function attribute, ‘name’.
> >
> Perhaps the OP means that 'name' is a variable which is bound to the
> name of the function/method, which is an attribute of self.blahbalah.
> 
> > (Aside: Please choose better example names, these make it rather
> > difficult to talk about.)
> >
> >> So:
> >> my function is:
> >> self.blahblah.name(arg1,arg2,arg3)
> >
> > Your *function* is ‘self.blahblah.name’.
> >
> > One possible way to express a *call* that function is
> > ‘self.blahblah.name(arg1, arg2, arg3)’.
> >
> If 'name' is bound to the name, then:
> 
>      func = getattr(self.blahblah, name)
>      func(arg1, arg2, arg3)
> 
> or just:
> 
>      getattr(self.blahblah, name)(arg1, arg2, arg3)
> 
> >> I read functools documentations, may be objictive usage and
> >> functionality differ, Do you have experience with objective usage ?
> >> http://docs.python.org/2/library/functools.html#partial-objects
> >
> > I don't understand what the question is. You have shown a way to call
> > your function; what do you want to do now?
> >
> >> I need to use it in my class,
> >
> > Feel free :-)
> >
> 





More information about the Python-list mailing list