There is a Connector class that has the following constructor:

 class Connector(): def __init__(self, filename='config.ini', section='mysql'): parser = ConfigParser() parser.read(filename) self.db = {} if parser.has_section(section): items = parser.items(section) for item in items: self.db[item[0]] = item[1] else: raise Exception('{0} not found in the {1}'.format(section, filename)) 

If i do

 if __name__ == '__main__': connector = Connector() 

in the same module where it lies, then everything works. However, when creating an object in another module, an error occurs:

 TypeError: 'module' object is not callable 

What's the matter ?

  • Give the full text of the error. - user194374
  • I realized that I can not import ... If you enter connector = Connector.Connector (), then everything is fine. How to avoid this specifying the module name before the class name? - faoxis
  • from Connector import Connector - user194374

1 answer 1

Rename the file with the class code Conector (module).

 from MyModule import Connector