NameError:未定义名称“username”

时间:2014-06-03 22:11:15

标签: python

我有以下代码,其中我试图遍历GerritInfo的每个条目并基于此添加逻辑但运行到下面的错误 任何人都可以建议这里有什么问题以及如何克服这个问题?

#!/usr/bin/python
GerritInfo = {'Assignee': username, 'RCAInfo': 'Provided', 'PLProductLine': 'LNX.LA.0.0', 'GerritInfo': [{'Url': 'https://review-android.company.com/761190', 'Status': 'MERGED', 'kw_ran': 'kw running', 'Info': 'ALREADY INTEGRATED', 'lookahead_ran': 'lookahead running'}, {'Url': 'https://review-android.company.com/777849', 'Status': 'NEW', 'kw_ran': 'kw did not run', 'Info': 'Available', 'lookahead_ran': 'lookahead running'}], 'CRId': '<a href="http://prism/CR/664310">664310</a>', 'CRStatus': Fix, 'RNotesStatus': 'Yes', 'TargetName': MSM8916, 'IsDevComplete': True}


if (('Not Provided' in GerritInfo['GerritInfo'][0]['Url'] or 'Wrong Gerrit Provided' in GerritInfo['GerritInfo'][0]['Url']) or ('NEW' in GerritInfo['GerritInfo'][0]['Status'] or 'ABANDONED' in GerritInfo['GerritInfo'][0]['Status'] or 'Yes' not in GerritInfo['RNotesStatus'] or 'Provided' not in GerritInfo['RCAInfo'] or 'False' in str(GerritInfo['IsDevComplete']))):
    print "Inside if"
else:
    print "in else"

错误: -

Traceback (most recent call last):
  File "infoloop.py", line 3, in <module>
    GerritInfo = {'Assignee': username, 'RCAInfo': 'Provided', 'PLProductLine': 'LNX.LA.0.0', 'GerritInfo': [{'Url': 'https://review-android.company.com/761190', 'Status': 'MERGED', 'kw_ran': 'kw running', 'Info': 'ALREADY INTEGRATED', 'lookahead_ran': 'lookahead running'}, {'Url': 'https://review-android.company.com/777849', 'Status': 'NEW', 'kw_ran': 'kw did not run', 'Info': 'Available', 'lookahead_ran': 'lookahead running'}], 'CRId': '<a href="http://prism/CR/664310">664310</a>', 'CRStatus': Fix, 'RNotesStatus': 'Yes', 'TargetName': MSM8916, 'IsDevComplete': True}
NameError: name 'username' is not defined

由于

1 个答案:

答案 0 :(得分:3)

如果您打算使用字符串值username,请定义变量"username"或添加引号"username"