Late initialization using __getattribute__
michele.simionato at gmail.com
Thu Sep 4 05:26:37 CEST 2008
On Sep 4, 12:26 am, bukzor <workithar... at gmail.com> wrote:
> I'm trying to optimize my number of connections by not fully
> initializing (read: not connecting) my connection until it's used in
> some way.
I had the same use case and I solved with a simple property. Here is
I have for pymssql:
if self._conn is None:
self._conn = _mssql.connect(self.host, self.user,self.passwd)
The connection is really instantiate only when you call self.conn to
perform the query, not when you instantiate the class.
More information about the Python-list