我收到一个[属性错误:模块'code'没有属性'主要']错误,但该属性显然存在。为什么?



我试图将Discord机器人程序链接到我创建的文本网关,但当我试图调用游戏本身的class时,它告诉我,

AttributeError: module 'code' has no attribute 'Main'

这是我的代码:

# bot.py
import code # Import the code for the actual game
main = code.Main() # Begin the game's processes
# code.py
class Main:
def __init__(self):
self.otherModule() # This module is used to continue the flow throughout the class

我看不出它出了什么问题。当我试图查找它时,我只被告知";给它上一堂课">

重命名code。模块code已经作为内置模块存在于Python3中。

Python 3.10.4
Type "help", "copyright", "credits" or "license" for more information.
>>> import code
>>> print(code)
<module 'code' from '/usr/lib/python3.10/code.py'>

来源:https://docs.python.org/3/library/code.html#module-代码

最新更新