u***8 发帖数: 1581 | 1 json is already :
{ "mem": [
{
"id":"v1",
"money":"v2",
"host":"v3"
}
}
I only need "id" and "host" to form a csv like this
id, host
"v1","v2"
"v3","v4"
like so. Can someone help me out? I am so water in python. wasted 3 hours!
| w****k 发帖数: 6244 | 2 import csv
with open('out.csv', 'wb') as f:
writer = csv.writer(f, delimiter=',',quotechar='"',quoting=csv.QUOTE_
ALL)
for item in dic.get("mem"):
writer.writerow([item.get('id'), item.get('host')])
【在 u***8 的大作中提到】 : json is already : : { "mem": [ : { : "id":"v1", : "money":"v2", : "host":"v3" : } : } : I only need "id" and "host" to form a csv like this : id, host
| u***8 发帖数: 1581 | 3 r u sure it works ?thanks!
【在 w****k 的大作中提到】 : import csv : with open('out.csv', 'wb') as f: : writer = csv.writer(f, delimiter=',',quotechar='"',quoting=csv.QUOTE_ : ALL) : for item in dic.get("mem"): : writer.writerow([item.get('id'), item.get('host')]) :
| u***8 发帖数: 1581 | |
|