简体   繁体   中英

Why do I keep getting the error “AttributeError: '_io.TextIOWrapper' object has no attribute 'writerows” when using csv module?

I am imported CSV and the way the documents told me to do it resulted in failures.

Here is the code that is having the problems.

outfile = open("D:/stock_information/processed data/standard_deviant.csv", "w")
write_outfile = csv.writer(outfile)

for i in range(len(all_standard_deviant_info)):
    outfile.writerows(all_standard_deviant_info[i][0])
    outfile.writerows(all_standard_deviant_info[i][1])

Does anyone know why it's saying .writerows doesn't exist?

You need to use,

write_outfile.writerows(all_standard_deviant_info[i][0])

Because outfile is just a file object not a csv.writer 's object.

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