测试文件import threadinga_list = []def a(): while True: a_list.append("A")threading.Thread(target=a).start()测试1.pyimport testfrom test import a_listimport timewhile True: print(a_list) time.sleep(1)如果我导入文件“test”并无限地将“A”附加到列表中并使用“test1”打印值,由于某种原因,test1的值将不会更新如何让 test1 识别列表已从文件“test”更新并使用文件“test1”打印出来我赶紧把这段代码分享在这里,我很抱歉。一些帮助会很好。我试着用谷歌搜索但我找不到任何东西
1 回答

慕码人2483693
TA贡献1860条经验 获得超9个赞
你忘记global了你的功能:
import threading
a_list = []
def a():
global a_list
while True:
a_list.append("A")
threading.Thread(target=a).start()
虽然我建议反对这样的代码。
当心:“这里有龙”
添加回答
举报
0/150
提交
取消