TypeError: 'module' object is not callable

前端 未结 11 1814
耶瑟儿~
耶瑟儿~ 2020-11-22 12:06
File \"C:\\Users\\Administrator\\Documents\\Mibot\\oops\\blinkserv.py\", line 82, in __init__
    self.serv = socket(AF_INET,SOCK_STREAM)
TypeError: \'module\' objec         


        
11条回答
  •  青春惊慌失措
    2020-11-22 12:33

    Short answer: You are calling a file/directory as a function instead of real function

    Read on:

    This kind of error happens when you import module thinking it as function and call it. So in python module is a .py file. Packages(directories) can also be considered as modules. Let's say I have a create.py file. In that file I have a function like this:

    #inside create.py
    def create():
      pass
    

    Now, in another code file if I do like this:

    #inside main.py file
    import create
    create() #here create refers to create.py , so create.create() would work here
    

    It gives this error as am calling the create.py file as a function. so I gotta do this:

    from create import create
    create() #now it works.
    

    Hope that helps! Happy Coding!

提交回复
热议问题