Barry Warsaw wrote: > On Wed, 2005-09-07 at 08:55, Nick Coghlan wrote: > > >>The leading 'p' (for 'positional') is necessary to get around the fact that >>$1 >>is currently an illegal identifier in a Template > > > That should be fixable. Ideally, $1 is better than $p1.
I also looked into the idea of adding formatting support to the string.Template syntax. Given a reimplementation of string.Template with the following pattern: pattern = r""" %(delim)s(?: (?P<escaped>%(delim)s) | # An escape sequence of two delimiters, or ( (\[(?P<format>[^%%]*)\])? # an optional simple format string, ( (?P<named>%(id)s) | # and a Python identifier, or {(?P<braced>%(id)s)} # a braced identifier ) ) | (?P<invalid>) # An ill-formed delimiter expr ) """ And "convert" functions modified to use "fmt" where "'%s'" is currently used, with "fmt" defined via: fmt = mo.group('format') if fmt is None: fmt = '%s' # Default to simple string format else: fmt = '%' + fmt The following works: Py> t = format.Template("$item: $[0.2f]quantity") Py> t.format(quantity=0.5, item='Bees') 'Bees: 0.50' Combining with a 'format' function similar to the one in my previous message, and an id pattern modified to permit numbers as identifiers: Py> format("$1: $[0.2f]2", 'Bees', 0.5) 'Bees: 0.50' Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com