[docs] Tutorial difficulty

Chris Coen chriscoen at bigpond.com
Sun Sep 11 04:51:03 CEST 2011


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()) and '!r' (apply 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20110911/8ce89386/attachment.html>


More information about the docs mailing list