Thursday, October 12, 2017

[Python3][Resolved] TypeError: 'module' object is not callable, module & inheritance

Source code

The files are in a package named person.

male.py
class Male():
    sex_chromosomes = "XY"
    def __init__(self):
        self.type = "male"
    def say(self):
        #super().say()
        print("I am a male")

man.py
from person import male

male = male()
male.say()

Problem

male is a module but not a class, it can't be called as a class to creating class instance, it should be a careless mistake.
man.py
from person import male

male = male.Male()
male.say()
A related error using this example :
[Python3][Resolved] NameError: name 'Male' is not defined, module & inheritance

Reference

https://stackoverflow.com/questions/4534438/typeerror-module-object-is-not-callable

No comments :

Post a Comment