1

I have a list of values that I would like to add (automatically) as individual headers in my csv file.

I cant seem to get the logic correct - this is what i have thus far:

unique_fields = ['buffcount', 'size', 'ctype', 'atype', 'idiameter', 'row', 'pstatus', 'perminal']

with open(r"C:\Temp\test2\new.csv", 'wb') as outfile:
   f = csv.writer(outfile, delimiter=',', quotechar='"')

   f.writerow(["FDomain", "CValue", "Descr", unique_fields])

This is what I want the headers to look like:

FDomain | CValue | Descr | buffcount | size | ctype | atype | idiameter | row | pstatus | perminal

What's the best way to add these list items as individual headers?

I've tried list comprehension ( fl for fl in unique_fields ) at the f.writerow function but I get a <generator object <genexpr> error

1 Answer 1

1

Try like this:

f.writerow(["FDomain", "CValue", "Descr"] + unique_fields)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.