[Python-3000] More PEP 3101 changes incoming

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Aug 17 03:16:20 CEST 2007


Jim Jewett wrote:
> You can't write int(s) if you're passing a mapping (or tuple) from
> someone else; at best you can copy the mapping and modify certain
> values.

Maybe this could be handled using a wrapper object that
takes a sequence or mapping and a collection of functions
to be applied to specified items.

    "i = {0}, x = {1}".format(convert(stuff, int, float))

or using names

    "i = {i}, x = {x}".format(convert(stuff, i = int, x = float))

This would have the advantage of allowing arbitrarily
complex conversions while keeping the potentially verbose
specifications of those conversions out of the format
string. Plus the convert() wrapper could be useful in its
own right for other things besides formatting.

--
Greg


More information about the Python-3000 mailing list