Search code examples
pythondictionaryget

can't get the value of something in a dict with a key


so i have this code

test = json.load(open('data.json'))
print (test)
print(test[MACadress])

and i can't get the value of MACadress, i already tried test.get(MACadress)

i get this error:

//this is test :

{'MACadress': '0x1c1bb5d3ce17', 'daate': '2020-03-19 17:33:19.715129', 'CPU': 2051.929375, 'mem': 26.0, 'disk': 57.1, 'process': 333, 'users': '1'}

//error message:

Traceback (most recent call last): File "recepteur_infos_machines.py", line 11, in print(test[MACadress]) NameError: name 'MACadress' is not defined


Solution

  • print(test["MACadress"]) the key is a string. Without quotes you are referencing a non-existent variable.