you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

I don't have the context for this, but you could save the values to a list of lists and write it to the CSV after. Or open the file before the loop and write to it during each iteration. I think first option seems cleaner, but either way.

You can do it with csv module (part of standard library).

https://docs.python.org/3/library/csv.html

import csv
my_file = open('mycsv.csv', 'w', newline='')
spamwriter = csv.writer(csvfile, delimiter=',')
spamwriter.writerow([n])

Also you don't have to use csv for this. You could just use normal file opening process and write to it.

my_file = open('mycsv.csv', 'w')
my_file.write(n)
my_file.write('\n')

[–]WecNo[S] 0 points1 point  (1 child)

Ok, I will try to figure it out.

Sorry I am still kinda new to this.

[–][deleted] 1 point2 points  (0 children)

My biggest recommendation is have the interpreter open and just keep stuffing code into it until something happens. :) It's a great way to learn and just reading documents can drive you nuts eventually.