[DB-SIG] PEP 249 clarification
M.-A. Lemburg
mal at egenix.com
Wed Apr 21 23:20:49 CEST 2010
Stefan C. Kremer wrote:
> Hi,
>
> The "fetchall()" command returns a list. Lists are mutable objects in python. Could a valid implementation return the same list object (with different contents) for multiple calls to fetchall() (with potentially different preceding execute queries)?
That would be a very unusual behavior in Python. Mutable objects
are normally not shared between function/method calls. If they
are shared, this needs to be documented. It is possible
(and common) to share immutable objects, though.
The DB-API uses the latter to implement am optimization in
the .execute() method: if you pass in the same command string
object in subsequent calls, the implementation can choose to
reuse the previously prepared access plan.
Some other examples (these are all True):
dict(some_dict) is not some_dict
list(some_list) is not some_list
tuple(some_tuple) is some_tuple
str(some_str) is some_str
--
Marc-Andre Lemburg
eGenix.com Professional Python Services directly from the Source
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the DB-SIG
mailing list