I need to get the value of the variable below that stores a dictionary, why do I get the answer (NameError: name 'variable' is not defined) ?
Exemple :
variable['txt'] = 'welcome'
print(variable)
on line #1 variable
is not defined. What you expect?
(Feb-24-2020, 11:36 AM)buran Wrote: [ -> ]on line #1 variable
is not defined. What you expect?
Do I need to receive the text in json format but still have the same error?
import json
my_var['João'] = '8887-7778'
print(json.dumps(my_var))
Just tell Python it's a dictionary. The syntax could be for list and so it is confused
variable = dict()
variable['txt'] = 'welcome'
print(variable)
Output:
{'txt': 'welcome'}