简体   繁体   English

如果 __name__ == "__main__": 失败; 为什么不 __main__ 打电话给我的课?

[英]if __name__ == "__main__": failing; why won't __main__ call my classes?

I have been simplifying this code and I am without words.我一直在简化这段代码,我一言不发。 Simply put, the file will not run to call the classes present, and by extension the functions within.简而言之,该文件不会运行以调用存在的类,并通过扩展调用其中的函数。 The error is something I have never come across and would like some clarity on, if someone could provide it, please.这个错误是我从未遇到过的,如果有人可以提供,请澄清一下。

class Server_Design:
    def __init__(self):
        self.intro_input()

    def intro_input(self):
        self.host = input('Host: ')
        self.port = input('Port: ')
        print("y")

if __name__ == "__main__":
    Server_Design()

COMMAND LINE OUTPUT:命令行输出:

    [SpyderKernelApp] ERROR | Exception in message handler:
    Traceback (most recent call last):
      File "C:\Users\ ----\anaconda3\lib\site-packages\spyder_kernels\comms\frontendcomm.py", line 164, in poll_one
        asyncio.run(handler(out_stream, ident, msg))
      File "C:\Users\ ----\anaconda3\lib\site-packages\nest_asyncio.py", line 33, in run
        task = asyncio.ensure_future(main)
      File "C:\Users\ ----\anaconda3\lib\asyncio\tasks.py", line 677, in ensure_future
        raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
    TypeError: An asyncio.Future, a coroutine or an awaitable is required
    [SpyderKernelApp] ERROR | Exception in message handler:
    Traceback (most recent call last):

repeating indefinitely无限重复

This error was fixed in Spyder 5.2.0 (released on November 2021).此错误已在 Spyder 5.2.0 (2021 年 11 月发布)中修复。 Please update to a more recent version by following the instructions posted here .请按照此处发布的说明更新到最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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