2013-05-26 116 views
0

以下功能似乎很简单,但我不断收到:NameError:全局名称“this_submit”没有定义

NameError: global name 'this_submit' is not defined.

想法?

def sort_nodes(): 

host_list=Popen(hosts_cmd.split(),stdout=PIPE).communicate()[0].strip() 
exec_list=Popen(exec_cmd.split(),stdout=PIPE).communicate()[0].strip() 
if submit_cmd == '': 
    submit_list = [x for x in host_list if x not in exec_list] 
else: 
    submit_list=Popen(submit_cmd.split(),stdout=PIPE).communicate()[0].strip() 
for host in host_list: 
    if host in exec_list: 
     this_exec == 'Exec' 
    else: 
     this_exec == '' 
    if host in submit_list: 
     this_submit == 'Submit' 
    else: 
     this_submit == '' 
    output="%s,%s,%s\n" % (host,this_submit,this_exec) 
    ofile.write(output) 
+0

我想你想用'='而不是'==' – Ven

回答

0

你写==,而不是=。修复它,一切都会好起来的。

1

正确的语法是:

this_submit = 'Submit' 

this_submit = '' 

Python中的单=是赋值运算符。

==检查两个操作数的值是否相等,如果是,则条件为真。

相关问题