简体   繁体   中英

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

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])

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.

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