2

I get the following error for the print statements. What is incorrect about the dictionary?

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'])
benvc
  • 14,448
  • 4
  • 33
  • 54
RSSregex
  • 179
  • 7
  • Did you read the error code? It tells you the problem. You don't have any variable named `true`. The boolean object you're looking for is, as blhsing mentions in his answer, is `True`, not `true`. Same for `False` vs `false. – PMende Feb 20 '19 at 18:29
  • Possible duplicate of [NameError: name 'true' is not defined](https://stackoverflow.com/questions/30095032/nameerror-name-true-is-not-defined) – Random Davis Feb 20 '19 at 18:29
  • Thanks for the responses. I did find out after I posted the issue here. I was thinking in terms of key/value pairs in a dictionary and was expecting all of the data in it to free form. – RSSregex Feb 21 '19 at 04:11

1 Answers1

2

In Python, you should use True and False for Boolean values of true and 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"
}
blhsing
  • 91,368
  • 6
  • 71
  • 106