string - Writing a row in Python, what is the best data structure to use? -


i trying write headers .csv file (1 row)

my current way of doing this, think inefficient

    headers = "color:," + color + ',' \               "state:," + state + ',' \               "age," + str(age)      writer.writerow((headers.split(',')) 

so first row of every csvfile looks like

color:, red, state:, california, age:, 22

is there better way in doing this, instead of string...

thanks!

you can skip string concatenation , make list instead of having split on commas.

headers = ['color:', color, 'state:', state, 'age:', str(age)] writer.writerow(headers) 

this accomplish have concerned data in header. accomplishing?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -