Partially initialized module 'csv' has no attribute 'writer' (most likely due to a circular import)

Viewed 2551

I tried many times but it showing same error, i dont know where is did mistake..

import csv

with open('student.csv','w',newline='') as f:
   w = csv.writer(f)
   w.writerow(['Rollno','Name','Marks'])
   w.writerow([101,'somesh',89])
   w.writerow([102,'yogesh',85])
   w.writerow([103,'akhilesh',75])
   w.writerow([874,'supreet',87])
2 Answers

This error is often related to the name of the .py file, as it is named as csv.py. When it tries to import csv, it imports its csv.py file which does not contain any csv.writer functions. This can be solved by simply changing the name of your .py file.

Just rename your csv.py file to csv_test.py for example.

Related