Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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 NameError:未定义类名,尽管已导入_Python_Python Import_Python Module - Fatal编程技术网

Python NameError:未定义类名,尽管已导入

Python NameError:未定义类名,尽管已导入,python,python-import,python-module,Python,Python Import,Python Module,我用Spyder编写了一个项目,其中包含几个模块文件,如tester.py和scheduler.py。我在tester.py中创建了以下类: class Tester(object): def run(self): pass 当我将Tester类导入scheduler.py时,出现了一个名称错误(我使用Anaconda提示符访问项目文件夹并运行python scheduler.py): 有人能帮我弄清楚吗,非常感谢 调度程序类将getter实例化为Tester类的实例。

我用Spyder编写了一个项目,其中包含几个模块文件,如tester.py和scheduler.py。我在tester.py中创建了以下类:

class Tester(object):
    def run(self):
        pass
当我将Tester类导入scheduler.py时,出现了一个名称错误(我使用Anaconda提示符访问项目文件夹并运行
python scheduler.py
):


有人能帮我弄清楚吗,非常感谢

调度程序类将getter实例化为Tester类的实例。 然后尝试在导入的Tester类上使用run方法。 这是不可能的,因为它是一个普通方法而不是类方法。 我想您应该在while循环中调用getter.run()而不是Tester.run()。 因此,您的计划程序将如下所示:

class Scheduler():
    def schedule_tester(self):
        getter = Tester()
        while True:
            getter.run() # not Tester.run()

请包含完整的错误消息。在哪个文件中创建了
class Tester
?错误消息很短。我都写了。class Tester在Tester.py中。对不起,我在帖子中犯了一个错误。最初的版本实际上是
getter.run()
。但仍然收到一条错误消息。这无法解释
namererror
class Scheduler():
    def schedule_tester(self):
        getter = Tester()
        while True:
            getter.run() # not Tester.run()