Enumerating formatting strings
Andrew Dalke
dalke at dalkescientific.com
Wed Apr 20 18:50:43 EDT 2005
Michael Spencer wrote:
> I have wrapped up my current understanding in the following class:
I see you assume that only \w+ can fit inside of a %()
in a format string. The actual Python code allows anything
up to the balanced closed parens.
>>> class Show:
... def __getitem__(self, text):
... print "Want", repr(text)
...
>>> "%(this(is)a.--test!)s" % Show()
Want 'this(is)a.--test!'
'None'
>>>
I found this useful for a templating library I once wrote
that allowed operations through a simple pipeline, like
%(doc.text|reformat(68)|indent(4))s
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list