![]() |
How to save data into next columns - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to save data into next columns (/thread-13432.html) |
How to save data into next columns - Prince_Bhatia - Oct-15-2018 hi, I am writing a csv file which appends data into rows like [attachment=483] but want it like this [attachment=484] I have list [] where i am appending the data and using it to to write file : def writefiles(alldata, filename): with open ("./"+ filename, "w") as csvfile: csvfile = csv.writer(csvfile, delimiter=",") csvfile.writerow("") for i in range(0, len(alldata)): csvfile.writerow(alldata[i]) writefiles(alldata, "Data.csv")How can i do this? RE: How to save data into next columns - wavic - Oct-15-2018 It's about how you construct your data. >>> import csv >>> data = [['a', 123, 123,123], ['b', 345, 345, 345]] >>> with open('/tmp/data.csv', 'w') as output: ... writer = csv.writer(output) ... for row in data: ... writer.writerow(row) ... 15 15 >>> with open('/tmp/data.csv', 'r') as data: ... for line in data: ... print(line) ... a,123,123,123 b,345,345,345 >>> RE: How to save data into next columns - Prince_Bhatia - Oct-15-2018 Oh no no.....i am appending data into csv and you have converted them to list , my columns are not in list they are just simple columns, how to convert them to list like you did it? RE: How to save data into next columns - wavic - Oct-15-2018 Read the data, convert it as you want and write it back. Just add to the first list as long as the first element of the data is 'a'. Same with the 'b's |