<div dir="ltr"><br><div class="gmail_quote">On Sun, Sep 11, 2011 at 05:51, Chris Coen <span dir="ltr">&lt;<a href="mailto:chriscoen@bigpond.com">chriscoen@bigpond.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<u></u>





<div bgcolor="#ffffff">
<div><font face="Arial" size="2">Dear Python Team.</font></div>
<div><font face="Arial" size="2">I am part way through the Python Tutorial v2.7.2 
and have found one difficulty which I think is worth reporting as 
follows:</font></div>
<div>Section = 7.1. Fancier Output Formatting</div>
<div>Copy of tutorial original content (which does not work giving an error 
message with last line : </div>
<div>&quot;ValueError: zero length field name in format&quot; ) :</div>
<div>
<p><tt><span>&#39;!s&#39;</span></tt> (apply <a title="str" href="http://docs.python.org/library/functions.html#str" target="_blank"><tt><span>str()</span></tt></a>) and <tt><span>&#39;!r&#39;</span></tt> (apply <a title="repr" href="http://docs.python.org/library/functions.html#repr" target="_blank"><tt><span>repr()</span></tt></a>) can be 
used to convert the value before it is formatted.</p>
<p><span>&gt;&gt;&gt; </span><span>import</span> <span>math</span><br><span>&gt;&gt;&gt; </span><span>print</span> <span>&#39;The value of PI is approximately 
{}.&#39;</span><span>.</span><span>format</span><span>(</span><span>math</span><span>.</span><span>pi</span><span>)</span><br><span>The value of PI is 
approximately 3.14159265359.</span><br><span>&gt;&gt;&gt; </span><span>print</span> <span>&#39;The value of PI is approximately 
{!r}.&#39;</span><span>.</span><span>format</span><span>(</span><span>math</span><span>.</span><span>pi</span><span>)</span><br><span>The value of PI is 
approximately 3.141592653589793.</span><br></p>
<div>
<div><pre>I think the python code in both the {} should be modified as follows :</pre><pre><p><span>&gt;&gt;&gt; </span><span>import</span> <span>math</span>
<span>&gt;&gt;&gt; </span><span>print</span> <span>&#39;The value of PI is approximately <font color="#800000">{0!s}.</font>&#39;</span><span>.</span><span>format</span><span>(</span><span>math</span><span>.</span><span>pi</span><span>)</span>
<span>The value of PI is approximately 3.14159265359.</span>
<span>&gt;&gt;&gt; </span><span>print</span> <span>&#39;The value of PI is approximately <font color="#800000">{0!r}.</font>&#39;</span><span>.</span><span>format</span><span>(</span><span>math</span><span>.</span><span>pi</span><span>)</span>
<span>The value of PI is approximately 3.141592653589793.</span></p><p><span></span> </p><p><span><font face="Arial" size="2">Trust this both helps and is correct.</font></span></p><p><span><font face="Arial" size="2"></font></span> </p>

<p><span><font face="Arial" size="2">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.</font></span></p><p><span><font face="Arial" size="2"></font></span> </p>

<p><span><font face="Arial" size="2">Best regards.   Chris Coen</font></span></p></pre></div></div></div></div></blockquote><div> <br></div></div>Hi Chris,<br><br>Which version of Python are you using to test this?<br>Please note that Python 2.7 added (something 2.6 didn&#39;t have) the ability to omit positional argument specifiers in format strings. Read: <a href="http://docs.python.org/library/string.html#formatstrings">http://docs.python.org/library/string.html#formatstrings</a> for more details<br>

<br>Eli<br><br><br></div>