gdogg371
gdogg371

Reputation: 4122

Replacing space between json.loads elements with comma

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

Answers (1)

amacleod
amacleod

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

Related Questions