Reputation: 5259
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
Upvotes: 3
Views: 8253
Reputation: 21
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
Upvotes: 1
Reputation: 77912
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.
Upvotes: 8