Black_Ram Black_Ram - 3 months ago 12
Python Question

TypeError: 'class' object is not callable

I have got:

MAIN SCRIPT:

import music.umm
UMM = music.umm.UMM()
UMM.read_information()


MODULE SCRIPT:

class UMM(object):

def read_information(self):
..some code
UMM.login()

UMM = UMM()


With this code, I get this error when I run main script:


TypeError: 'UMM' object is not callable


How do I fix it?

EDIT:

I remove from the module this line:

UMM = UMM()


Now, the main script RUN the function module, but if the script module goes to another function, I get this error:


TypeError: unbound method login() must be called with UMM instance as
first argument (got nothing instead)

Answer

I try to help despite of the few information you give us.

A 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 could imagine that this would exactly yield the 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.