[docs] documentation error/bug 7.1. Fancier Output Formatting

Sandro Tosi sandro.tosi at gmail.com
Tue Apr 19 21:35:24 CEST 2011


Hi Don,

On Mon, Mar 7, 2011 at 03:18, Dan Orton <d.orton5963 at gmail.com> wrote:
> hello,
> I think I may have found a bug in the documentation under 7.1. Fancier
> Output Formatting

http://docs.python.org/tutorial/inputoutput.html#fancier-output-formatting

> as I am a beginner, I really do not have many ideas on how to fix it.
> also as this is a simpleton error, there may already be discussion on a fix.
> 1) You will see the following code.
>
>>>> 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.
>
> 2)
> When entered into Python, it complains
> Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)

you're reading documentation for 2.7 and running the example on 2.6 .
format() has changed between those 2 versions:

$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> print 'The value of PI is approximately {0}.'.format(math.pi)
The value of PI is approximately 3.14159265359.

for 2.6 you have to number explicitly the fields, while in 2.7 onward
you don't need to (it will take the order in which they are passed).

Regards,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi


More information about the docs mailing list