我在Raspbian上运行Python3。当我尝试在Thonny或raspberry pi终端中运行程序时,出现错误提示
File "main.py", line 4, in <module>
import getRoom
AttributeError: module 'getRoom' has no attribute 'currentRoom'
我不知道为什么会这样,如下面的代码所示,我拥有使它正常运行所需的一切
main.py
import getRoom
def getStage(room):
if room == 'start':
getRoom.start()
while vars.is_alive:
cls()
getStage(getRoom.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
这些只是https://github.com/FerisJumbo/AdventureGames上的整个代码的片段
我仍然对模块如何不具有属性感到困惑
currentroom
即使已定义。我在main.py
while循环中尝试过
只使用getRoom.currentroom
答案 0 :(得分:1)
const player = new TTMPlayer(resource["MJJOG.TTM"], ctx);
const arr = [0,1,2,3,4,4,4,5];
const firstFn = arr.reduceRight(
(nextCallback, num) => () => player.playscript(num, nextCallback),
() => console.log('done')
);
firstFn();
会导入getRoom.py
,尽管对此没有做任何事情。此循环导入导致main
的解析提前结束,这意味着getRoom.py
从未定义。只需将currentRoom()
中的import main, os, time
更改为getRoom.py
。