functions, classes, bound, unbound?
bbxx789_05ss at yahoo.com
Sun Mar 25 22:22:36 CEST 2007
On Mar 25, 3:00 am, irs... at gmail.com wrote:
> On Mar 25, 9:13 am, "7stud" <bbxx789_0... at yahoo.com> wrote:
> > MyClass.someFunc
> > 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.
That doesn't seem to fit what GvR was talking about. From this
methObj = Test.__dict__["greet"]
I get this output:
Traceback (most recent call last):
File "test1.py", line 7, in ?
AttributeError: 'function' object has no attribute 'im_self'
So it doesn't look like a method object gets created when you retrieve
a function from a class like that. Compare to:
methObj = Test.greet
> Since the method is an attribute of a class, what other kinds of means
> are you expecting to be possible?
I'm just wondering why in this description:
When a user-defined method object is created by retrieving a user-
defined function object from a class, its im_self attribute is None
and the method object is said to be unbound. When one is created by
retrieving a user-defined function object from a class via one of its
instances, its im_self attribute is the instance, and the method
object is said to be bound.
GvR didn't explicitly mention using the class name to retrieve the
function object in the first sentence. It seems to imply there are
other ways to retrieve the function object from the class that cause a
method object to be created.
More information about the Python-list