Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.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 3中运行函数时,未定义_Python - Fatal编程技术网

名称错误:名称';测试';尝试在导入的模块/脚本Python 3中运行函数时,未定义

名称错误:名称';测试';尝试在导入的模块/脚本Python 3中运行函数时,未定义,python,Python,我将GUI脚本和逻辑脚本分开以使事情更简单(使用VSCode),当我运行GUI脚本时,我调用逻辑脚本中的函数:GUI.destroy_window(),它反过来调用GUI中的函数: def destroy_window(): test.destroy() 然而,尽管我之前在运行GUI时在GUI中定义了测试,但我得到了以下结果: 注意:我已将这两个脚本相互导入,并将测试设置为全局。函数destroy\u窗口的中不知道变量test 尝试将对象传递给函数: def destroy_windo

我将GUI脚本和逻辑脚本分开以使事情更简单(使用VSCode),当我运行GUI脚本时,我调用逻辑脚本中的函数:
GUI.destroy_window()
,它反过来调用GUI中的函数:

def destroy_window():
    test.destroy()
然而,尽管我之前在运行GUI时在GUI中定义了测试,但我得到了以下结果:


注意:我已将这两个脚本相互导入,并将测试设置为全局。

函数
destroy\u窗口的中不知道变量
test

尝试将对象传递给函数:

def destroy_window(window):
    window.destroy()

destroy_window(test)

你能告诉我们完整的代码吗?调用destroy_window()函数的位置?
def create_monitor(monitor_url,monitor_counter_arg):website_url=monitor_url=requests.get(website_url)#如果我能找到一种方法,在没有全局url的情况下使用get_content的访问标题_html=url.content html_parser=etree.HTMLParser()tree=etree.fromstring(url\u html,html\u parser)title=tree.findtext('.//title')copyfile('default\u config.py',f'config{monitor\u counter\u arg}.py')mod importlib.import\u模块(f'config{monitor\u counter\u arg})keys=mod.keys GUI.destroy\u window()
当两个模块分别导入另一个模块时,需要小心。我可以制造错误。我不确定这是否是您的案例,但这似乎来自您的“注释部分”,因此请查看此问题,以探索将create\u monitor称为logic.create\u monitor()的想法GUI@ZenKoh在问题的细节中添加评论中发布的所有代码,并缩进,以便更容易查看,等等。
def destroy_window(window):
    window.destroy()

destroy_window(test)