0

Maybe this question is too naive, but is giving me a hard time!. I want to write 2 float values and a list of int to a row in csv file in a loop. The file may or may not exist before an attempt is made to write in it. In case it does not, a new file should be created. This is what I am doing:

f = open('stat.csv','a')
try:
    writer=csv.writer(f,delimiter=' ',quoting=csv.QUOTE_MINIMAL)
    writer.writerow((some_float1,some_float2,alist))
finally:
    f.close()

where alist = [2,3,4,5]. I am getting the following output:

 some_float1 some_float2 "[2,3,4,5]"

What I want is this:

 some_float1 some_float2 2 3 4 5

i.e. I would like to get rid of the "", the square brackets and make the delimiter consistent throughout. Any suggestions ?

1 Answer 1

5

How about:

writer.writerow([some_float1, some_float2] + alist)
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.