[docs] Tutorial difficulty

Eli Bendersky eliben at gmail.com
Tue Sep 13 10:16:59 CEST 2011


On Sun, Sep 11, 2011 at 05:51, Chris Coen <chriscoen at bigpond.com> wrote:

> **
> Dear Python Team.
> I am part way through the Python Tutorial v2.7.2 and have found one
> difficulty which I think is worth reporting as follows:
> Section = 7.1. Fancier Output Formatting
> Copy of tutorial original content (which does not work giving an error
> message with last line :
> "ValueError: zero length field name in format" ) :
>
> '!s' (apply str() <http://docs.python.org/library/functions.html#str>) and
> '!r' (apply repr() <http://docs.python.org/library/functions.html#repr>)
> can be used to convert the value before it is formatted.
>
> >>> import math
> >>> print 'The value of PI is approximately {}.'.format(math.pi)
> The value of PI is approximately 3.14159265359.
> >>> print 'The value of PI is approximately {!r}.'.format(math.pi)
> The value of PI is approximately 3.141592653589793.
>
> I think the python code in both the {} should be modified as follows :
>
> >>> import math>>> print 'The value of PI is approximately {0!s}.'.format(math.pi)The value of PI is approximately 3.14159265359.>>> print 'The value of PI is approximately {0!r}.'.format(math.pi)The value of PI is approximately 3.141592653589793.
>
>
>
> Trust this both helps and is correct.
>
>
>
> I appreciate the efforts taken to offer the tutorial and often think how difficult it must be to keep the tutorial in step with the current version of Python.
>
>
>
> Best regards.   Chris Coen
>
>
Hi Chris,

Which version of Python are you using to test this?
Please note that Python 2.7 added (something 2.6 didn't have) the ability to
omit positional argument specifiers in format strings. Read:
http://docs.python.org/library/string.html#formatstrings for more details

Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20110913/66459f73/attachment-0001.html>


More information about the docs mailing list