简体   繁体   中英

module 'csv' has no attribute 'writer'

I have a bit of code giving me trouble I was just trying to import my text file to a CSV file but I m getting an error stating module CSV has no attribute 'writer'

Here is my code:

import csv 
f = open("Sales.txt")
x = f.readlines()
s = []`
print (f)
for i in x:
i = i.replace(","," ")
j = i.replace(" ",",")
s.append(j)
csvex =csv.write(open("Sample_CSV","w"),delimiter=',',quoting=csv.QUOTE_ALL)
csevx.writerow(s)

can someone figure this out what kind of error is this

It is not writer in your code change line:

csvex =csv.write(open("Sample_CSV","w"),delimiter=',',quoting=csv.QUOTE_ALL)

to:

csvex =csv.writer(open("Sample_CSV","w"),delimiter=',',quoting=csv.QUOTE_ALL)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM