AQDeveloper AQDeveloper - 3 months ago 13
Python Question

Psycopg2 shows error

From my understanding psycopg2 comes installed with the Python 2.7. When I run the following module it returns an error.

import psycopg2
import sys

conn = none

Traceback (most recent call last):
File "C:/Users/aqureshi/Desktop/Programming/psycopg2.py", line 1, in<module>
import psycopg2
File "C:/Users/aqureshi/Desktop/Programming\psycopg2.py", line 4, in<module>
conn = none
NameError: name 'none' is not defined

Answer

The "none" is a built in constant which needs to be capitalised:

import psycopg2
import sys

conn = None

The error occurs because the Python interpreter thinks you are trying to reference a variable named 'none' which does not exist in your code.

Comments