Distinguishing attributes and methods

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Dec 10 00:54:46 EST 2007


On Sun, 09 Dec 2007 12:44:46 -0800, MonkeeSage wrote:

> On Dec 8, 4:11 pm, Bruno Desthuilliers
> <bdesth.quelquech... at free.quelquepart.fr> wrote:
>> MonkeeSage a écrit :
> You're talking about the result of calling a.a(), I'm talking about
> what the attribute "a" on the object "a" is. Which is a callable
> attribute, which by definition is called a "method" in the standard
> sense [1].  You can make a distinction between a "method object" and
> "any other possible callable object," but I wasn't using such a
> distinction, I was using the standard definition. So my point holds.
> When you see a.a(), because of pythons calling convention "()" you
> know that "a" is a method of object "a".

No you don't know that.  It's only a method of object `a` if it is really
a method bound to object `a` and not just a "data attribute" that happens
to be callable.

> Again, I am using the common definition. I understand that you can
> make an attribute callable in different ways than just the standard
> machinery of "def symbol(self):" (those other techniques are what I
> was referring to above by "metaprogramming"). But how it is made
> callable doesn't matter (nor does how it is looked up). Once it is
> callable, it fits the defintion of "method" I'm using. In future, I'll
> try to be clear when I'm referring to something python specific or to
> a general CS concept.

Your definition of "method" is a bit odd then.  The general CS sense of
"method" requires the method to be bound to the object and not just be a
random callable.  Let's see an example:

In [469]: a = collections.defaultdict(int)

In [470]: callable(a.default_factory)
Out[470]: True

In [471]: a.default_factory(42)
Out[471]: 42

`a.default_factory` is callable but hardly a method of `a` or `defaultdict`
but a "data attribute" that happens to be callable.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list