template strings for matching?

Tino Wildenhain tino at wildenhain.de
Thu Oct 9 10:02:21 EDT 2008


skip at pobox.com wrote:
>     Tino> Yeah, its a bit hard to spot:
> 
>     Tino> http://docs.python.org/library/stdtypes.html#string-formatting-operations
> 
> That shows how to use the template formatting as it currently exists.  To my
> knowledge there is no support for the inverse operation, which is what Joe
> asked about.  Given a string and a format string assign the elements of the
> string which correspond to the template elements to key/value pairs in a
> dictionary.
> 
??? can you elaborate? I don't see the problem.

"%(foo)s" % mapping

just calls get("foo") on mapping so if you have a dictionary
with all possible values it just works. If you want to do
some fancy stuff just subclass and change the method
call appropriately.

Regards
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20081009/656b6a48/attachment-0001.bin>


More information about the Python-list mailing list