Python 表示模块没有位于同一目录中的属性
我在Raspbian上运行Python 3。当我试图用Thonny或raspberry pi终端运行我的程序时,我得到一个错误Python 表示模块没有位于同一目录中的属性,python,python-3.x,Python,Python 3.x,我在Raspbian上运行Python 3。当我试图用Thonny或raspberry pi终端运行我的程序时,我得到一个错误 File "main.py", line 4, in <module> import getRoom AttributeError: module 'getRoom' has no attribute 'currentRoom' getRoom.py currentroom = 'start' def start(): print(""" H
File "main.py", line 4, in <module>
import getRoom
AttributeError: module 'getRoom' has no attribute 'currentRoom'
getRoom.py
currentroom = 'start'
def start():
print("""
Hello User and welcome to Cedrics Adventure!
First Things first what is that you want to
be called?
""")
vars.name = input('>')
cls()
print("Hello {}, Please press enter to continue".format(vars.name))
none = input(">")
vars.currentroom = 'courtyard'
有一个名为vars
的类存储currentRoom
def currentRoom():
return currentroom
这些只是正在运行的整个代码的片段
我仍然对模块如何没有属性感到困惑
currentroom
即使已定义。我在main.py
while循环中进行了尝试
只使用
getRoom.currentroom
getRoom.py
导入main
,而不使用它。此循环导入导致getRoom.py
的解析提前结束,这意味着从未定义currentRoom()
。只需将getRoom.py
中的import main,os,time
更改为import os,time,您可以显示类vars
的定义吗?该错误意味着不存在属于该类的currentroom
变量。
def currentRoom():
return currentroom