简体   繁体   中英

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.

The application is for Windows and not for 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). 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. Your main function would then be,

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. Do instead:

os.system('cls')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM