简体   繁体   English

NameError:未定义名称“用户名”

[英]NameError: name 'username' is not defined

I have the following code in which am trying to loop over every entry of GerritInfo and add logic based on that but running into below error can anyone suggest what is wrong here and how to overcome this? 我有以下代码,试图在该代码上循环遍历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"

Error:- 错误:-

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

Thanks 谢谢

无论是定义变量username或添加引号"username" ,如果你打算使用字符串值"username"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM