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
Post a Comment