[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling an instance method defined without any 'self' parameter

class A:
    def foo():
        print 'Hello, world!'

a = A()print       # <unbound method>print       #
<bound method of <__main__.A instance at 0x7efc462a7830>>print
type( # <type 'instancemethod'>           # TypeError: foo() takes no arguments (1 given)           # TypeError: unbound method foo() must be called
with A instance as first argument (got nothing instead)

Clearly, foo is an instance method. I know one should use @staticmethod for
declaring a method static. The question here is, given the above code, is
there any way to call foo?

Python 2.7