Posts

Showing posts from June, 2005

Singleton pattern for a database connection

I think I understood Singleton 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 #just to test logjam