성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] The Windows Registry Adventure #1: ...
[정성태] systemd for Developers I ; https:/...
[정성태] 엄밀히 object 타입의 인스턴스가 다른 타입으로 형변환 가능...
[정성태] 아래의 글에서 나오는 "Windows Application Pa...
[정성태] The history of calling conventions,...
[정성태] Secure and Deploy .NET Windows Form...
[정성태] Get Started with Milvus Vector DB i...
[정성태] cyberark/PipeViewer - A tool that...
[정성태] WinForms in a 64-Bit world – our st...
[정성태] 예제에서 SELECT_SQL도 내부적으로는 SqlCommand/...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>python - TypeError: '...' object is not callable</h1> <p> 무심코, 다음과 같이 코드를 작성했는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > import sys len = 147 if <span style='color: blue; font-weight: bold'>len(sys.argv)</span> >= 2: len = int(sys.argv[1]) </pre> <br /> 실행 시 이런 오류가 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>python3 test.py 130</span> Traceback (most recent call last): File "test.py", line 6, in <module> if len(sys.argv) >= 2: TypeError: 'int' object is not callable </pre> <br /> 이상하군요, 분명히 <a target='tab' href='https://docs.python.org/3/library/functions.html#len'>len 내장 함수</a>는 sys.argv 목록에 대해 요소 수를 반환할 텐데 예외가 발생하는 것입니다. 눈썰미 좋으신 분들은 벌써 아셨겠지만 ^^ 바로 위에 정의한,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > len = 147 </pre> <br /> 코드 때문입니다. 저 코드로 인해 len 내장함수는 더 이상 함수가 아닌 변수로 인식되기 때문에 len(sys.argv) 코드가 변수에 대한 호출처럼 바뀐 것입니다.<br /> <br /> 어찌 보면 저런 것은 "len = 147"이라는 코드 수행 시 오류를 발생시켜 주면 좋지 않을까 싶은데요, 대개의 언어들이 식별자로 부적합한 기준을 (내장 함수가 아닌) 예약어(reserved keywords)에 한해 적용하기 때문에 파이썬의 이런 처리가 타당한 것은 맞습니다.<br /> <br /> 단지, 파이썬 언어 자체가 그다지 많은 예약어를 갖고 있지 않다는 것이 문제인데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Reserved Keywords ; <a target='tab' href='https://realpython.com/lessons/reserved-keywords/'>https://realpython.com/lessons/reserved-keywords/</a> // 파이썬 3.6 기준 False def if raise None del import return True elif in try and else is while as except lambda with assert finally nonlocal yield break for not class from or continue global pass </pre> <br /> 이로 인해 다른 언어 개발자들은 예약어로 알고 있는 int 조차도 파이썬에서는 내장 함수이므로 식별자로 사용하는 것이 가능해 재수가 없다면 ^^ 이런 오류를 만나게 될 것입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > int = 5 print(int) number = int('6') print(number) /* 오류 Traceback (most recent call last): File "test.py", line 7, in <module> number = int('6') TypeError: 'int' object is not callable */ </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
9724
(왼쪽의 숫자를 입력해야 합니다.)