[Python-3000] More PEP 3101 changes incoming

Jim Jewett jimjjewett at gmail.com
Fri Aug 10 16:27:07 CEST 2007


On 8/9/07, Eric V. Smith <eric+python-dev at trueblade.com> wrote:

> If you want:
>
> x = 3
> "{0:f}".format(x)
>
> then be explicit and write:
>
> "{0:f}".format(float(x))

Because then you can't really create formatting strings.  Instead of

    >>> print("The high temperature at {place:s}, on {date:YYYY-MM-DD}
was {temp:f}" % tempsdict)
    >>> print("{name} scored {score:f}" % locals())

You would have to write

    >>> _tempsdict_copy = dict(tempsdict)
    >>> _tempsdict_copy['place'] = str(_tempsdict_copy['place'])
    >>> _tempsdict_copy['date'] =
    ...         datetime.date(_tempsdict_copy['date']).isoformat()
    >>> _tempsdict_copy['temp'] = float(_tempsdict_copy['temp'])
    >>> print("The high temperature at {place}, on {date} was {temp}"
% _tempsdict_copy)

    >>> _f_score = float(score)
    >>> print("{name} scored {score}" % locals())

-jJ


More information about the Python-3000 mailing list