Reputation: 4122
I have the following code:
for myvar in json.loads(myjson):
print myvar['var1'], myvar['var2'], myvar['var3']
This is printing results in the manner of:
var1 var2 var3
But I would like it it print it in the manner of:
var1,var2,var3
How can I replace the space between the elements of the json load with a comma?
Thanks
Upvotes: 0
Views: 251
Reputation: 1560
You could put the values in a list, and then use the join
method of str
.
vars = [myvar['var1'], myvar['var2'], myvar['var3']]
print ",".join(vars)
Upvotes: 1