[Python-3000] String formating operations in python 3k
Barry Warsaw
barry at python.org
Tue Apr 4 21:03:13 CEST 2006
On Mon, 2006-04-03 at 15:23 -0500, Ian Bicking wrote:
> This is all wandering off-topic, except that all these cases make me
> think that different kinds of wrapping are very useful. For instance,
> if you want to make sure everything is quoted before being inserted:
>
> class EscapingWrapper:
> def __init__(self, d):
> self.d = d
> def __getitem__(self, item):
> return cgi.escape(str(self.d[item]), 1)
>
> Or if you want expressions:
>
> class EvalingWrapper:
> def __init__(self, d):
> self.d = d
> def __getitem__(self, item):
> return eval(item, d)
>
> Then you do:
>
> string.Template(pattern).substitute(EscapingWrapper(EvalingWrapper(locals()))
I like this. I'd probably not utilize EvalingWrapper, just because I'd
really want to keep translatable strings really really simple. I think
most translators can grok simple $-substitutions because they've seen
those in many other languages.
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 309 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-3000/attachments/20060404/3cbbad15/attachment.pgp
More information about the Python-3000
mailing list