简体   繁体   English

如何修复“ TypeError:'模块'对象不可调用”?

[英]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.

相关问题 类型错误:“模块”object 不可调用,我该如何解决? - TypeError: 'module' object is not callable , how can i fix it? 如何修复 TypeError 说“模块”对象不可调用 - How to fix a TypeError saying 'module' object is not callable 如何修复此类型错误:“模块”object 不可调用 - how to fix this TypeError: 'module' object is not callable 我该如何解决这个“TypeError: ‘str’ object is not callable”错误? - How do I fix this "TypeError: 'str' object is not callable" error? 使用sagemath:如何解决此错误TypeError:“ list”对象不可调用 - Using sagemath: how do I fix this error TypeError: 'list' object is not callable TypeError: 'Add' object 不可调用,我该如何解决? - TypeError: 'Add' object is not callable, How can I fix it? TypeError:“模块”对象不是可调用错误。 我该如何解决这个问题? - TypeError: 'module' object is not callable error. How do I solve this issue? 尝试使用 rmsprop 优化器时,如何解决“TypeError: 'module' object is not callable”问题? - How do I resolve the "TypeError: 'module' object is not callable" issue when trying to use the rmsprop optimizer? 如何解决Python TypeError:&#39;module&#39;对象不可调用? - How can I resolve Python TypeError: 'module' object is not callable? 如何修复TypeError:&#39;str&#39;对象不可调用 - how to fix TypeError: 'str' object is not callable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM