名称错误:名称“进程”;未定义(python)

发布于 2024-11-26 04:32:47 字数 505 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2024-12-03 04:32:47

您发布的代码段似乎来自此处发布的cmp.py脚本(链接目前已关闭)。

该脚本正在命令行上运行,需要为 -b--benchmark 指定有效值。您要么没有指定一个,要么指定了一个无效的。

可以通过添加 else 情况来修改脚本以显示更有用的错误,但除非您使用适当的值,否则它仍然无法工作。

例如,您可以尝试以下操作:

python cmp.py --benchmark perlbench

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:

python cmp.py --benchmark perlbench
又怨 2024-12-03 04:32:47

这意味着您的块

if options.benchmark == 'perlbench':
     process = Mybench.perlbench
elif options.benchmark == 'bzip2':
     process = Mybench.bzip2
elif options.benchmark == 'gcc':
     process = Mybench.gcc

与任何 options.benchmark 都不匹配,因此变量 process 从未被分配任何内容。您需要

else:
    process = Mybench.<somedefault>

在其末尾添加一个(当然根据需要填写)。或者,如果这是无效的情况,您也许可以提出例外。

That means that your block

if options.benchmark == 'perlbench':
     process = Mybench.perlbench
elif options.benchmark == 'bzip2':
     process = Mybench.bzip2
elif options.benchmark == 'gcc':
     process = Mybench.gcc

didn't match any of options.benchmark so the variable process was never assigned anything. You need to throw an

else:
    process = Mybench.<somedefault>

on the end of it (of course filling in <somedefault> as appropriate). Or if that's an invalid case, you could raise an exception, perhaps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文