简体   繁体   中英

object not callable python when parsing a json response

I have a response from a URL which is of this format.

'history': {'all': [[u'09 Aug', 1,5'],[u'16 Aug', 2, 6]]}

And code is :

response = urllib.urlopen(url)
data = json.loads(response.read())
print data["fixture_history"]['all']
customObject = MyObject (
                           history = data["history"]['all']
                        )

Printing works but in my custom class I am seeing this error :

    history = data["history"]['all']
TypeError: 'module' object is not callable

My class is :

class MyObject:
    #init
    def _init_(self,history):
        self.hstory = history

Printing works but in my custom class I am seeing this error : TypeError: 'module' object is not callable

I bet your your class is defined in a module named MyObject.py and that you imported it as import MyObject instead of from MyObject import MyObject , so in your calling code, name MyObject is bound to the module, not the class.

If you Class is defined in a different Module please make sure that that you have imported it the right way ie. you need to use from X import Y format but not Import X and expect it to work as if we do it that way we need to let python know the module we are calling it from.

And i am not very sure but i think the typo in the constructor might case the issue as stated bigOTHER

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM