Mohan Randeniya
Mohan Randeniya

Reputation: 17

Output CSV has comma after every character in python

Here is my source code

import csv
import datetime

csvdate = [datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')]

csvFile = open('test.csv', 'a', newline="")
writer = csv.writer(csvFile)
writer.writerow("----------------------------------------------------")
writer.writerow(csvdate)
writer.writerow("Form Action")
writer.writerow("Form URL")
writer.writerow("Suspected Request")
csvFile.close()

And the output

-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
2020-04-14 10:12:51
F,o,r,m, ,A,c,t,i,o,n
F,o,r,m, ,U,R,L
S,u,s,p,e,c,t,e,d, ,R,e,q,u,e,s,t

If it put csv.writerows, all the characters would be in a single column.

Upvotes: 0

Views: 707

Answers (1)

Sri
Sri

Reputation: 2328

Try this. Your code is treating the string as a list

writer.writerow(["Form Action"])
writer.writerow(["Form URL"])
writer.writerow(["Suspected Request"])

Upvotes: 2

Related Questions