[ANN] istring 1.0.1 released; announce list created
Artur Skura
arturs at iidea.pl
Wed Mar 6 07:10:58 EST 2002
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""")
db.query(qry)
To make this even cleaner, we could write a function that took a
regular raw string with istring interpolation, then made an istring
of
it and submitted the query, like this:
(3) db.iquery("""SELECT foo, bar
FROM $table
WHERE rsrc_id = $rsrc_id
AND name = $.name""")
It's not something revolutionary, just useful. If it was in standard Python,
I would probably use it every day.
Regards,
Artur
--
http://www.wolneprogramy.org
More information about the Python-list
mailing list