Unable to write to CSV.Please let me know.

Asked 2 years ago, Updated 2 years ago, 72 views

I would like to do all the i and j, but it does not run with the following syntax:
This is Python 3.6.How should I fix it?

l=[1,2,3,4,5]
g = [6,7,8,9,10]
p = [1,2,3]
q = [4,5,6]

import csv
f = open ('data99.csv', 'ab')
csvWriter=csv.writer(f)

listData=[ ]
for i in range (len(l)):
   for jin range (len(p)):
      a=l[i]*p[j]+g[i]*q[j]
      listData.append(a)
         writer.writerow (listData)
f.close()

python python3 csv

2022-09-29 22:34

1 Answers

A csv file is a text file that contains comma-separated data columns.
Nevertheless, according to the code of the question,

f=open('data99.csv', 'ab')

and the destination file are open in binary mode (b).That's why you don't get the data (text) you think you're getting.Also, I wonder if I need to put the file in postscript mode (a).

Try changing the above line of code as follows:

f=open('data99.csv', 'w')


2022-09-29 22:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.