开发者

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:

sys开发者_StackOverflow社区tem.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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜