[DB-SIG] pyformat Parameter Style

M.-A. Lemburg mal at lemburg.com
Sat May 10 20:54:30 EDT 2003


Chris Cogdon wrote:
> 
> On Saturday, May 10, 2003, at 10:23 US/Pacific, Andy Todd wrote:
> 
>> Is there a definitive specification of the pyformat parameter style 
>> anywhere?
>>
>> The usual sources come up dry. It is mentioned in the DB-API 
>> specification (http://www.python.org/peps/pep-0249.html) but not defined.
>>
>> It seems from observation that one should simply put '%(<parameter 
>> name>)s' in the query string and then pass a mapping with a 
>> corresponding key when calling the execute method. But I'd just like 
>> to make absolutely sure.
>>
>> In particular, I'm curious if the 's' actually means anything (like 
>> string?). Should I be using different characters for different data 
>> types, and if so, which ones?
> 
> You just about nailed it. You should ALWAYS use 's', too, regardless of 
> the data type.

The DB API says "Python extended format codes" meaning that all
valid Python formatting codes (including their parameters) may
be used.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source  (#1, May 10 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
EuroPython 2003, Charleroi, Belgium:                        45 days left




More information about the DB-SIG mailing list