Встроенные методы или функции не реализуют протокол дескриптора, который лишает возможности делать материал как это:
>>> class C(object):
... id = id
...
>>> C().id()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: id() takes exactly one argument (0 given)
Однако можно создать маленькое, связывают дескриптор, который делает это возможным:
>>> from types import MethodType
>>> class bind(object):
... def __init__(self, callable):
... self.callable = callable
... def __get__(self, obj, type=None):
... if obj is None:
... return self
... return MethodType(self.callable, obj, type)
...
>>> class C(object):
... id = bind(id)
...
>>> C().id()
7414064
The Zild Database Library, "a thread-safe high level multi-database connection pool library", looks very promising.
Previously I suggested that SQL Relay could be used to do this, amongst many other useful things, such as
If the MySQL library is dynamically linked this can be done without recompiling the application.
When I last looked in 2009, the mailing list suggested SQL Relay might not be fully ready for production use, but that appears to have changed.