Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57327

Re: functools and objective usage

Date 2013-10-23 00:56 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: functools and objective usage
References <1382478989.4873.6.camel@debian> <7w8uxleyya.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.1389.1382486172.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 22/10/2013 23:13, Ben Finney wrote:
> Mohsen Pahlevanzadeh <mohsen@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 :-)
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: functools and objective usage MRAB <python@mrabarnett.plus.com> - 2013-10-23 00:56 +0100

csiph-web