[英]Don't understand why this NameError: name 'null' is not defined exception occurs
I'm testing a new code and I'm getting the error below.我正在测试新代码,但出现以下错误。 If I change the field "name: null" for something like "name: abc" it works.
如果我将字段“名称:null”更改为“名称:abc”之类的内容,它就会起作用。 Any idea?
任何的想法? How I can skip/workaround this "null" issue?
我如何跳过/解决这个“空”问题?
Traceback (most recent call last):
File "<string>", line 3, in <module>
NameError: name 'null' is not defined
Here's my code:这是我的代码:
data = [{"id": 111,
"description": "",
"name": null,
"name_with_namespace": "Zzzz",
"path": "Zzzz"
},
{"id": 222,
"description": "",
"name": "xp-demo-gradle",
"name_with_namespace": "xp-demo-gradle",
"path": "xp-demo-gradle"
}]
for request in data:
lista = []
request["id"]
paragraph = "id: " + str(request["id"]) + "; Path: " + request["path"] + "; Name: " + request["name"]
artifact = {
"requested_by": "RequestFetcher",
"argument": {
"topic": {
"id": 2
},
"key": str(request["id"]),
"title": "ID " + str(request["id"]),
"text": paragraph,
"cached": True,
"_links": [
{
"href": "https://gitlab.local.com/api/v4/projects/" + str(request["name"]),
"rel": "self",
"method": "GET"
}
],
}
}
lista.append(artifact)
print(lista)
null
is not a keyword in Python. null
不是 Python 中的关键字。 You should either make it a string (eg 'name': 'null'
) or use None
instead您应该将其设为字符串(例如
'name': 'null'
)或使用None
代替
I modified the script to use the json URL instead of add the data directly into the script and then it worked fine.我修改了脚本以使用 json URL 而不是将数据直接添加到脚本中,然后它运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.