functions, classes, bound, unbound?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Mar 25 16:54:41 EDT 2007


En Sun, 25 Mar 2007 17:22:36 -0300, 7stud <bbxx789_05ss at yahoo.com>  
escribió:

> On Mar 25, 3:00 am, irs... at gmail.com wrote:
>> On Mar 25, 9:13 am, "7stud" <bbxx789_0... at yahoo.com> wrote:
>>
>> > Is there some other way to retrieve a user-defined function object
>> > from a class other than using the class name or an instance?
>>
>> What Steven B. already said, MyClass.__dict__['someFunc'], is a
>> different way than MyClass.someFunc that produces different results.
>
> methObj = Test.__dict__["greet"]
> print methObj.im_self
>
> Traceback (most recent call last):
>   File "test1.py", line 7, in ?
>     print methObj.im_self
> AttributeError: 'function' object has no attribute 'im_self'

Because this way, you get a function, not a method. I'd say "read  
something about descriptors" but...

Nicolas Bourbaki [a collective of french mathematicians writing under that  
alias] said on a book about set theory: Any school boy can understand all  
of this with a minimum of effort, but for truly understanding what we are  
talking about, around four years of prior training on mathematics may be  
required. (I can't find the exact citation).

I suggest first learn to use Python and then try to understand how it does  
what it does, along the way, and looking for answers when you have a  
question.

-- 
Gabriel Genellina




More information about the Python-list mailing list