Answer the question
In order to leave comments, you need to log in
Why is the error being reproduced that the 'json' module does not have a 'dumps' attribute?
Hello.
There was a need in python to work with JSON,
the code is below
#!/usr/bin/python
import json
part_nums = ['ECA-1EHG102','CL05B103KB5NNNC','CC0402KRX5R8BB104']
def json_list(list):
lst = []
for pn in list:
d = {}
d['mpn']=pn
lst.append(d)
return json.dumps(lst)
print(json_list(part_nums))
AttributeError: module 'json' has no attribute 'dumps'
Answer the question
In order to leave comments, you need to log in
I rolled up the simplejson module,
as a result it will turn out something like this
#!/usr/bin/python
import simplejson as json
part_nums = ['ECA-1EHG102','CL05B103KB5NNNC','CC0402KRX5R8BB104']
def json_list(list):
lst = []
for pn in list:
d = {}
d['mpn']=pn
lst.append(d)
return json.dumps(lst)
print(json_list(part_nums))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question