python - 不明白为什么会出现这个 NameError: name 'null' is not defined 异常
问题描述
我正在测试一个新代码,我收到以下错误。如果我将字段“name:null”更改为“name:abc”之类的内容,它会起作用。任何想法?我如何跳过/解决这个“空”问题?
Traceback (most recent call last):
File "<string>", line 3, in <module>
NameError: name 'null' is not defined
这是我的代码:
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
不是 Python 中的关键字。您应该将其设为字符串(例如'name': 'null'
)或None
改用
推荐阅读
- python - 使用 Python Pandas 从数据框中获取总 values_count
- javascript - javascript:从谷歌驱动器播放文件
- html - 垂直居中
在向上滚动动画内
- javascript - 它不是提取数组“整数”的第一个元素,而是提取所有其他元素。为什么??另外我该如何改进这段代码?
- swift - 在导航堆栈中保留容器视图的内容
- javascript - forEach 循环从数组中提取元素并推入新数组
- r - 如何关联因子和列表?
- python - 无法跨 csv 文件中的列写入数据
- android - 如何在android studio中启用模拟器?
- excel - 运行时错误 5