名称错误:名称“进程”;未定义(python)
我有一个 python 脚本,如下所示:
if options.benchmark == 'perlbench':
process = Mybench.perlbench
elif options.benchmark == 'bzip2':
process = Mybench.bzip2
elif options.benchmark == 'gcc':
process = Mybench.gcc
....
np = 1
....
for i in xrange(np):
...
system.cpu[i].workload = process[i]
但是我收到此错误:
system.cpu[i].workload = process[i]
NameError: name 'process' is not defined
有关如何解决该问题的任何想法吗?我不是Python专家。
I have a python script which looks like:
if options.benchmark == 'perlbench':
process = Mybench.perlbench
elif options.benchmark == 'bzip2':
process = Mybench.bzip2
elif options.benchmark == 'gcc':
process = Mybench.gcc
....
np = 1
....
for i in xrange(np):
...
system.cpu[i].workload = process[i]
However I get this error:
system.cpu[i].workload = process[i]
NameError: name 'process' is not defined
Any idea on how to fix that? I am not an expert in python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您发布的代码段似乎来自此处发布的
cmp.py
脚本(链接目前已关闭)。该脚本正在命令行上运行,需要为
-b
或--benchmark
指定有效值。您要么没有指定一个,要么指定了一个无效的。可以通过添加
else
情况来修改脚本以显示更有用的错误,但除非您使用适当的值,否则它仍然无法工作。例如,您可以尝试以下操作:
The snippet you've posted appears to be from the
cmp.py
script posted here (link currently down).This script is being run on the command line and requires a valid value to be specified for
-b
or--benchmark
. You are either not specifying one or are specifying an invalid one.The script may be modified by adding an
else
case to display a more useful error, but it still won't work unless you use an appropriate value.For example, you could try this:
这意味着您的块
与任何
options.benchmark
都不匹配,因此变量process
从未被分配任何内容。您需要在其末尾添加一个(当然根据需要填写
)。或者,如果这是无效的情况,您也许可以提出例外。That means that your block
didn't match any of
options.benchmark
so the variableprocess
was never assigned anything. You need to throw anon the end of it (of course filling in
<somedefault>
as appropriate). Or if that's an invalid case, you could raise an exception, perhaps.