escaping/encoding/formatting in python

John Nagle nagle at animats.com
Wed May 23 14:19:55 EDT 2012


On 4/5/2012 10:10 PM, Steve Howell wrote:
> On Apr 5, 9:59 pm, rusi<rustompm... at gmail.com>  wrote:
>> On Apr 6, 6:56 am, Steve Howell<showel... at yahoo.com>  wrote:

> You've one-upped me with 2-to-the-N backspace escaping.

    Early attempts at UNIX word processing, "nroff" and "troff",
suffered from that problem, due to a badly designed macro system.

    A question in language design is whether to escape or quote.
Do you write

	"X = %d" % (n,))

or

	"X = " + str(n)

In general, for anything but output formatting, the second scales
better.  Regular expressions have a bad case of the first.
For a quoted alternative to regular expression syntax, see
SNOBOL or Icon.   SNOBOL allows naming patterns, and those patterns
can then be used as components of other patterns.  SNOBOL
is obsolete, but that approach produced much more readable
code.

				John Nagle



More information about the Python-list mailing list