gpt4 book ai didi

python - 尝试打印包含多个字典的列表内容时出错

转载 作者:太空宇宙 更新时间:2023-11-04 02:05:41 27 4
gpt4 key购买 nike

打印语句出现以下错误。字典有什么不对的地方?

Traceback (most recent call last):
File "/home/main.py", line 8, in
"enabled": true, NameError: name 'true' is not defined ...Program finished with exit code 1
Press ENTER to exit console.


gcblist =[
{
"band": "5",
"channel": 155,
"clients": 0,
"country": "United States",
"device": "wlan0",
"enabled": true,
"fbo": false,
"fbo_active": false,
"name": "5.0GHz",
"ssids": [
"TestWiFi"
],
"txpower": "30"
},
{
"band": "2.4",
"channel": 1,
"clients": 0,
"country": "United States",
"device": "wlan1",
"enabled": true,
"fbo": true,
"fbo_active": false,
"name": "2.4GHz",
"ssids": [
"TestWiFi"
],
"txpower": "30"
}
]
for item in gcblist:
print (item)
print (item['device'])

最佳答案

在 Python 中,您应该使用 TrueFalse 作为 bool 值的 true 和 false:

gcblist =[
{
"band": "5",
"channel": 155,
"clients": 0,
"country": "United States",
"device": "wlan0",
"enabled": True,
"fbo": False,
"fbo_active": False,
"name": "5.0GHz",
"ssids": [
"TestWiFi"
],
"txpower": "30"
},
{
"band": "2.4",
"channel": 1,
"clients": 0,
"country": "United States",
"device": "wlan1",
"enabled": True,
"fbo": True,
"fbo_active": False,
"name": "2.4GHz",
"ssids": [
"TestWiFi"
],
"txpower": "30"
}

关于python - 尝试打印包含多个字典的列表内容时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54792926/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com