This post originated from an RSS feed registered with Python Buzz
by Ian Bicking.
Original Post: % interpolation
Feed Title: Ian Bicking
Feed URL: http://www.ianbicking.org/feeds/atom.xml
Feed Description: Thoughts on Python and Programming.
It sure would be convenient if, in addition to %s, we could use %h or %u in strings, where '%h' % obj was equivalent to cgi.escape(str(obj), 1) and '%u' % obj was like urllib.quote(str(obj)). Where would it end? you might ask... but I think it could end right there. Other kinds of quoting (e.g., SQL quoting) are handled in a more context-sensitive fashion. Encoding (like base64, printed-quotable, and others) is handled nicely with the .encode and .decode methods. But I don't think URL and entity encoding are good candidates for "encoding" since you are only quoting particular values, not encoding whole representations. Or maybe they would be reasonable as codecs...? Maybe '%:html:s' % obj could mean str(obj).encode('html')...
Though maybe Guido would find this all to be too useful ;)