gpt4 book ai didi

python - 赋值前引用的局部变量 'sresult'

转载 作者:行者123 更新时间:2023-12-01 06:17:12 25 4
gpt4 key购买 nike

我在尝试使用 PP 时遇到了多个问题。我正在运行 python2.6 和 pp 1.6.0 rc3。使用以下测试代码:

import pp
nodes=('mosura02','mosura03','mosura04','mosura05','mosura06',
'mosura09','mosura10','mosura11','mosura12')

def pptester():
js=pp.Server(ppservers=nodes)
tmp=[]
for i in range(200):
tmp.append(js.submit(ppworktest,(),(),('os',)))
return tmp

def ppworktest():
return os.system("uname -a")

给我以下结果:

In [10]: Exception in thread run_local:Traceback (most recent call last):  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner    self.run()  File "/usr/lib64/python2.6/threading.py", line 477, in run    self.__target(*self.__args, **self.__kwargs)  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local    job.finalize(sresult)UnboundLocalError: local variable 'sresult' referenced before assignmentException in thread run_local:Traceback (most recent call last):  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner    self.run()  File "/usr/lib64/python2.6/threading.py", line 477, in run    self.__target(*self.__args, **self.__kwargs)  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local    job.finalize(sresult)UnboundLocalError: local variable 'sresult' referenced before assignmentException in thread run_local:Traceback (most recent call last):  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner    self.run()  File "/usr/lib64/python2.6/threading.py", line 477, in run    self.__target(*self.__args, **self.__kwargs)  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local    job.finalize(sresult)UnboundLocalError: local variable 'sresult' referenced before assignmentException in thread run_local:Traceback (most recent call last):  File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner    self.run()  File "/usr/lib64/python2.6/threading.py", line 477, in run    self.__target(*self.__args, **self.__kwargs)  File "/home/wkerzend/python_coala/lib/python2.6/site-packages/pp.py", line 751, in _run_local    job.finalize(sresult)UnboundLocalError: local variable 'sresult' referenced before assignment

非常感谢任何帮助。

最佳答案

我无法阅读您的代码,因为它的格式不正确,但我可以告诉您您的确切问题:您试图从函数内部修改名为“sresult”的全局变量,但您没有添加此行到函数的开头:

全局结果

如果你没有声明一个全局变量,当你试图在函数内分配它时,Python会假设它是函数的本地变量,所以当你尝试修改或访问它时,Python会提示你还没有“绑定(bind)局部变量”(即为其赋值或赋予其值)。

关于python - 赋值前引用的局部变量 'sresult',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2616220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com