Distinguishing attributes and methods

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Dec 10 08:41:31 EST 2007


On Mon, 10 Dec 2007 03:56:10 -0800, MonkeeSage wrote:

> So, when I say that all callable attributes (or to be more precise, all
> callable attributes bound to objects other than toplevel) are "methods,"
> what am I missing?

Everything that isn't a method but is callable.

class Callable(object):
    def __call__(self):
        return oct(id(self))


class Foo(object):
    aclass = type('Parrot', (object,), {})
    atype = int
    ainstance = Callable()
    afunction = None  # this is tricky...
    def __init__(self):  # a method
        self.afunction = lambda n: n+1



-- 
Steven



More information about the Python-list mailing list