Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'csv' is not defined

Tags:

python

csv

I am new to Python, and I want to write a csv file, that lists the roots of my equation. I am working on Sage. My code is :

with open('out.csv', 'w') as f:
    c = csv.writer(f)
    c.writerows(root)

The error I am getting is " NameError: name 'csv' is not defined "

Can anybody help please?

like image 609
Nicole Avatar asked Jul 06 '17 15:07

Nicole


People also ask

How do you fix NameError name is not defined?

The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.

How do you define a NameError in Python?

NameError is a kind of error in python that occurs when executing a function, variable, library or string without quotes that have been typed in the code without any previous Declaration. When the interpreter, upon execution, cannot identify the global or a local name, it throws a NameError.

What is a Quotechar?

quotechar specifies the character used to surround fields that contain the delimiter character. The default is a double quote ( ' " ' ). escapechar specifies the character used to escape the delimiter character, in case quotes aren't used. The default is no escape character.


1 Answers

csv is not a builtin, although it's part of the standard library. You need to import it:

import csv

# your code
like image 78
Moses Koledoye Avatar answered Oct 08 '22 08:10

Moses Koledoye