A
A
Artyom Arutyunyann2021-01-14 13:59:16
Python
Artyom Arutyunyann, 2021-01-14 13:59:16

How to fix KeyError in Python?

Hello! Need help
Code:

import json
data = {
" Name 1 " : ["a1", "a2", "a3"],
" Name 2 " : ["a1", "a2", "a3"]
}
json_data = json.dumps(data)
json_dec = json.loads(json_data)

print(json_dec[" Name 1 "])

# Ответ:  KeyError : " Name 1 "

Help me please))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2021-01-14
@bacon

There is no error here. And for the keys with spaces, they kick.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question