[英]How do i fix “TypeError: 'module' object is not callable”?
I'm tring to create a python app for a school project, when i finished programming this error popped out and i dont know how to fix it. 我正在尝试为学校项目创建python应用程序,当我完成编程后会弹出此错误,而且我不知道如何解决。
The application is for Windows and not for linux. 该应用程序适用于Windows,不适用于Linux。 I alredy saw other posts on this error, but no one helped me. 我确实看到了有关此错误的其他帖子,但没有人帮助我。
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
this is the first part and last part of my code, my code isn't structured on multiple files, only this. 这是我代码的第一部分和最后一部分,我的代码不是基于多个文件构建的,仅此而已。
in the console the output is 在控制台中,输出为
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>
Can anyone help me with this? 谁能帮我这个? Thanks 谢谢
You're getting the error because os.sys
is a module and not a callable object (a function). 由于os.sys
是模块而不是可调用对象(函数),因此出现错误。 Essentially, what you are doing is equivalent to 从本质上讲,您所做的等同于
import A
A()
You can consider using os.system
instead, which executes a given command in a subshell. 您可以考虑改用os.system
,它在子shell中执行给定命令。 Your main
function would then be, 您的main
功能将是
def main():
while True:
os.system('cls')
Manifesto()
print("[...]\n> ")
...
os.sys
refers to the sys
module imported into the os
module, not the os.system
function that you are looking for. os.sys
是指导入到os
模块中的sys
模块,而不是您要查找的os.system
函数。 Do instead: 改为:
os.system('cls')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.