Kyle Wilkins
Kyle Wilkins

Reputation: 77

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?

Upvotes: 6

Views: 14007

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174756

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.

Upvotes: 8

Related Questions