December 2nd, 2012, 01:56 PM
Join Date: Dec 2012
Time spent in forums: 7 m 17 sec
Reputation Power: 0
Class variables for sqlite
This should be an easy question, I am trying to make a class for managing sqlite connections with python.
I have this so far (not to much
connection = None
cursor = None
def __init__(self, db_name, db_user):
self.connection = sqlite3.connect(db_name)
self.cursor = connection.cursor()
self.cursor.execute('SELECT * FROM questions');
I have tried to create the __del__ method as a destructor, in order to get rid of the connection with the database.
But I don't know how to declare those two variables as class variables in order to be used by the methods.
This is the error I get by creating an instance of the "Engine" class:
NameError: global name 'connection' is not defined
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method Engine.__del__ of <Engine.Engine instance at 0x7fb3a3e70cf8>> ignored
Any idea would be appreciated!
Thank you in advance!