[ANN] istring 1.0.1 released; announce list created
Gerhard Häring
gerhard at bigfoot.de
Wed Mar 6 08:04:47 EST 2002
Artur Skura wrote in comp.lang.python:
> Michael Ströder wrote:
>>>>>>s = i("Value is $n")
>>
>> Maybe it's me but I can't see the advantage over using
>>
>> >>> s = "Value is %s" % (n)
>>
>> How about providing a more complex example illustrating the benefits
>> of istring?
>
> Should I paste from their page? ;)
>
> Why would I want to interpolate variables when I could use %s
> notation?
>
> Ask yourself which query is clearer:
>
> (1) db.query("""SELECT foo, bar
> FROM %s
> WHERE rsrc_id = %s
> AND name = '%s'" % (table, rsrc_id, name))
>
> Or:
>
> (2) qry = istring("""SELECT foo, bar
> FROM $table
> WHERE rsrc_id = $rsrc_id
> AND name = $.name""")
^^^^^^^
There's a reason for cursor.execute(query_string, parameters) being in
the DB-API. Only the DB module can know how to put the parameters
there correctly with quoting and all.
Gerhard
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
More information about the Python-list
mailing list