0

ERROR:

Traceback (most recent call last):
  File "C:/Users/Mathew/Desktop/Python/PROJECT PRGRMS/defo.py", line 1, in <module>
    import csv
  File "C:/Users/Mathew/Desktop/Python/PROJECT PRGRMS\csv.py", line 7, in <module>
    with open(csv_path,"rb") as f_obj:
NameError: name 'csv_path' is not defined

CODE:

import csv

with open('emp.csv','w') as emp_file:
    w=csv.writer(file,delimiter=',')
    w.writerow(['Jane Thomas', 'Accounting', 'November'])
    print('RECORD WRITTEN SUCCESSFULLY')
    enter code here
MSalters
  • 173,980
  • 10
  • 155
  • 350
Lois Mathew
  • 7
  • 1
  • 1
  • 4

2 Answers2

4

Your problem is you have a csv.py in your working directory, and Python imports it instead of the standard library csv module, which you mean to use.

Your csv.py itself has that name error.

Rename csv.py to e.g. csv_test.py and you're good to go.

AKX
  • 152,115
  • 15
  • 115
  • 172
2

You've named one of your files "csv.py" which means that when you do import csv you import that file rather than the csv module from the standard lib.

Paul Hankin
  • 54,811
  • 11
  • 92
  • 118