sharing objects between classes

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Jan 28 12:09:17 EST 2008


Diez B. Roggisch a écrit :
> Gerardo Herzig wrote:
> 
>> Hi all. Im wondering the way to share a database connection between some
>> classes:
>>
>> So far, i came up with a simple class schema, where each class means
>> each different relation, i mean i have the follow classes
>>
>> class Database(object):
>>   ## make the connection
>>   self.conn = make_conn(....)
>>
>> class Table(object):
>>   def get_fields:
>>     ....
>>
(snip)
> 
> Take a look at the sources of e.g. SQLObject and how they do it (in SO, the
> concept is called "HUB")
> 
And while you're at it, take a look at SQLAlchemy too, and ask yourself 
if you really need to roll your own solution !-)



More information about the Python-list mailing list