[英]How do i fix “TypeError: 'module' object is not callable”?
我正在嘗試為學校項目創建python應用程序,當我完成編程后會彈出此錯誤,而且我不知道如何解決。
該應用程序適用於Windows,不適用於Linux。 我確實看到了有關此錯誤的其他帖子,但沒有人幫助我。
1 import os
2 from sys import *
3 from msvcrt import *
4 from webbrowser import *
5
6 def main():
7 while True:
8 os.sys('cls')
9 Manifesto()
10 print("[...]\n> ")
11 article = input("")
12 if article == 1:
[...] [...]
240 def wait():
241 msvcrt.getch()
242
243 if __name__ == '__main__':
244 main()
245
這是我代碼的第一部分和最后一部分,我的代碼不是基於多個文件構建的,僅此而已。
在控制台中,輸出為
C:\Users\John\Documents\Python>python costituzione.py
Traceback (most recent call last):
File "costituzione.py", line 244, in <module>
if __name__ == '__main__':
File "costituzione.py", line 10, in main
while True:
TypeError: 'module' object is not callable
C:\Users\John\Documents\Python>
誰能幫我這個? 謝謝
由於os.sys
是模塊而不是可調用對象(函數),因此出現錯誤。 從本質上講,您所做的等同於
import A
A()
您可以考慮改用os.system
,它在子shell中執行給定命令。 您的main
功能將是
def main():
while True:
os.system('cls')
Manifesto()
print("[...]\n> ")
...
os.sys
是指導入到os
模塊中的sys
模塊,而不是您要查找的os.system
函數。 改為:
os.system('cls')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.