TypeError: 'class' object is not callable
An SSCCE could look like
umm.py:
class UMM(object):
def login(self):
print("login()")
def read_information(self):
print("read_info() 1")
UMM.login()
print("read_info() 2")
main script:
import umm
umm = umm.UMM()
umm.read_information()
I didn't test it, but I imagine that this would yield exactly the following exception
TypeError: unbound method login() must be called with UMM instance as first argument (got nothing instead)
The reason is that UMM.login()
is a method which expects to be called via an instance of the object.
Inside read_information()
, you have self
as a concrete object instance. So you could replace the call
UMM.login()
with
self.login()
in order to fulfill all dependencies.
A call to UMM.login()
would try to call login()
without a object instance to work on. This would work with a @staticmethod
or a @classmethod
, but not with a regular bound method.
This is how I do it:
# Module Code
class MyClass(object):
def foo(self):
print "Foo"
# Client Code
from MyClass import MyClass
inst = MyClass()
inst.foo()