Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 表示模块没有位于同一目录中的属性_Python_Python 3.x - Fatal编程技术网

Python 表示模块没有位于同一目录中的属性

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

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