The Artima Developer Community
Sponsored Link

Python Buzz Forum
Sigleton pattern for a database connection

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Baiju M

Posts: 225
Nickname: baijum81
Registered: Aug, 2004

Baiju M is a new user
Sigleton pattern for a database connection Posted: Jun 19, 2005 9:30 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Baiju M.
Original Post: Sigleton pattern for a database connection
Feed Title: Programming life without Python(?)
Feed URL: http://baijum81.livejournal.com/data/rss
Feed Description: Programming life without Python(?)
Latest Python Buzz Posts
Latest Python Buzz Posts by Baiju M
Latest Posts From Programming life without Python(?)

Advertisement
I think I understood Sigleton pattern, any suggestion?



from pyPgSQL import PgSQL

class Database(object):
_sigletons = {}
def __new__(cls):
if cls not in cls._sigletons:
cls._connection = PgSQL.connect(database='dbname',
user='username',
password='passwd',
host='hostname')
cls._sigletons[cls] = object.__new__(cls)
pass
return cls._sigletons[cls]

def __init__(self):
self.connection = Database._connection
pass

def cursor(self):
return self.connection.cursor()

#other methods follows here

Read: Sigleton pattern for a database connection

Topic: I'm Back Previous Topic   Next Topic Topic: [GameCube] Super Monkey Ball

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use