<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Dear fellow Pythonians, | | I just stumbled upon the following unexpected behavior: | | class TestType(type): | def Foo(self): return 'TestType Foo' | class Test(object): | __metaclass__ = TestType | def Foo(self): return 'Test Foo' | t = Test() | print t.Foo() | print Test.Foo() | | This will produce: | Test Foo | Traceback (most recent call last): | File "test.py", line 8, in <module> | print Test.Foo() | TypeError: unbound method Foo() must be called with Test instance as | first argument (got nothing instead) | | I can imagine why this is happening, and that there is no easy | solution, but it is not what I was expecting.
Regardless of which Foo you expect to be called, both require an instance argument to be bound to the paramenter 'self'. print Test.Foo(t) # will print same as t.Foo() tjr -- http://mail.python.org/mailman/listinfo/python-list