On 2/8/06, adam johnson <[EMAIL PROTECTED]> wrote: > Thanks for you answer. > > I was under the impression that you could tack methods onto an object at any > time, your example almost works with old style classes and would with a > function instead of a method. > > >>> class A: > ... def __init__(self): > ... self.__call__ = A.hello > ... def hello(self): > ... print "Hello, world!" > ... > >>> a = A() > >>> a() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: unbound method hello() must be called with A instance as first > argument (got nothing instead) > >>> a(a) > Hello, world! > >>> > > So now all I need to know is why now with new style classes the special > functions need to be defined on the class instead of attached to the > instance at any time. > don't need do like above!
>>> class A: ... def __init__(self): ... A.__call__ = A.hello ... def hello(self): ... print "Hello, world!" >>> a = A() >>> a() Hello, world! You should review the bound method and unbound method. -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit -- http://mail.python.org/mailman/listinfo/python-list