(Error) TypeError: 'module' object is not callable
<문제발생>
<상황 1>
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-86-a3daef88415e> in <module> 2 3 test = ["2015-03-01"] # 테스트를 위한 데이터 수집 구간 ----> 4 for date in tqdm, notebook(test): 5 news_arrange_url = "https://news.naver.com/main/history/mainnews/list.nhn" 6 news_list_date_page_url = news_arrange_url + "?date=" + date TypeError: 'module' object is not callable
<상황 2>
File "C:\Users\Administrator\Documents\Mibot\oops\blinkserv.py", line 82, in __init__ self.serv = socket(AF_INET,SOCK_STREAM) TypeError: 'module' object is not callable
This is what the error message means:
It says module object is not callable, because your code is calling a module object. A module object is the type of thing you get when you import a module. What you were trying to do is to call a class object within the module object that happens to have the same name as the module that contains it.
Here is a way to logically break down this sort of error:
- "module object is not callable. Python is telling me my code trying to call something that cannot be called. What is my code trying to call?"
- "The code is trying to call on socket. That should be callable! Is the variable socket is what I think it is?`
- I should print out what socket is and check print socket
<해결방법>
import 한 모듈을 class처럼 사용하려 해서 발생한 에러였다.
import 한 modlue는 class가 아니기에 class처럼 사용하면 안된다.
import 할 파일
AAA.py
class AAA(object):
어쩌구저쩌구...
b.py
import AAA
class b(object):
aaa = AAA() <= 에러발생
aaa = AAA.AAA() <= OK
<결론>
import한 모듈과 class 이름을 컴퓨터가 구별 가능하도록 정의해야 한다.