说模块没有相同目录中的属性

时间:2018-11-03 21:13:57

标签: python python-3.x

我在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

1 个答案:

答案 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