Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 2nd, 2012, 01:56 PM
tikoti tikoti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 tikoti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 17 sec
Reputation Power: 0
Class variables for sqlite

Hi!

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 )

Code:
import sqlite3

class Engine:
  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');

  def __del__(self):
    self.cursor.close()
    self.connection.close()


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!

Reply With Quote
  #2  
Old December 2nd, 2012, 03:01 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,354 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 8 h 21 m 53 sec
Reputation Power: 383
I suggest you try
http://pypi.python.org/pypi/pysqlite/
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old December 2nd, 2012, 05:25 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,354 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 8 h 21 m 53 sec
Reputation Power: 383
Still a better idea, you won't be tied to a specific back end data base, I think,
http://wiki.python.org/moin/ODBC

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Class variables for sqlite

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap