Hello, I'm very new to Python -- going through theTutorial <http://docs.python.org/tutorial/index.html> athttp://docs.python.org/tutorial/inputoutput.html -- using 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] I think the following is wrong: >>> print 'We are the {} who say "{}!"'.format('knights', 'Ni') We are the knights who say "Ni!" and should be: >>> print 'We are the {0} who say "{1}!"'.format('knights', 'Ni') We are the knights who say "Ni!" or am i missing something? You may be hearing a lot more from me. Cheers, -- Martin Feuchtwanger, PhD martinf@underhill.ca 604-732-3384 x 206 Underhill Geomatics Ltd. www.underhill.ca 210A, 3430 Brighton Ave. Burnaby, BC V5A 3H4
Hi Martin, On Fri, Apr 8, 2011 at 00:08, Martin Feuchtwanger <martinf@underhill.ca> wrote:
Hello,
I'm very new to Python -- going through the Tutorial at http://docs.python.org/tutorial/inputoutput.html -- using 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
I think the following is wrong:
print 'We are the {} who say "{}!"'.format('knights', 'Ni') We are the knights who say "Ni!"
and should be:
print 'We are the {0} who say "{1}!"'.format('knights', 'Ni') We are the knights who say "Ni!"
or am i missing something?
Benjamin already replied to the other email, and I'm here just to reply also to this email. Why do you think you have to explicitly state the position of the objects in the {} format? the numbers can be use to specify a position of the objects passed to the string, but if you want to print them as they are passed, there's no need to enumerate them. Regards, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
Hi Sandro, Benjamin, et al., Maybe you didn't notice -- i was using 2.6.4 IDLE 2.6.4
print 'We are the {} who say "{}!"'.format('knights', 'Ni')
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> print 'We are the {} who say "{}!"'.format('knights', 'Ni') ValueError: zero length field name in format If you're wondering why i'm using 2.6... I was following the advice on http://wiki.python.org/moin/BeginnersGuide/Download so i downloaded and installed 2.6.4 on my windows work computer. I worked thru the web-based tutorial http://docs.python.org/tutorial/ and all was well until i got to the "knights of ni" example, hence my first email query. Interestingly, on the weekend, when i decided to install python on my home computer, i never saw any advice re stability on windows {i now realize it is because, silly me, i was getting advice on two different python.org web sites}, so i downloaded and installed 3.2 on it. Unfortunately, none of the print examples in the web-based tutorial http://docs.python.org/tutorial/ work on 3.2 Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
print 'We are the {} who say "{}!"'.format('knights', 'Ni') SyntaxError: invalid syntax
Now, i notice that the web tutorial is for python 2.7, and i'm well aware, from other parts of the web site, that there are significant changes from python 2 to python 3, and, yes, i know that in python 3 print follows strict function syntax, but may i suggest to you, and maybe to the entire docs/wiki team, * That each tutorial have this added at the beginning: "Note that this tutorial is version N and many of the examples will not work with version N-1 or version N+1 because the silly bunts at python.org like to invent a new kind of python with each release". * That you explain on both wiki.python.org and docs.python.org that, although they (docs and wiki) look the same they are different web sites and contain conflicting information. Thank you, one confused cat, Martin Feuchtwanger, PhD martinf@underhill.ca 604-732-3384 x 206 Underhill Geomatics Ltd. www.underhill.ca 210A, 3430 Brighton Ave. Burnaby, BC V5A 3H4 On 11/04/2011 11:34 AM, Sandro Tosi wrote:
Hi Martin,
On Fri, Apr 8, 2011 at 00:08, Martin Feuchtwanger<martinf@underhill.ca> wrote:
Hello,
I'm very new to Python -- going through the Tutorial at http://docs.python.org/tutorial/inputoutput.html -- using 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
I think the following is wrong:
print 'We are the {} who say "{}!"'.format('knights', 'Ni') We are the knights who say "Ni!"
and should be:
print 'We are the {0} who say "{1}!"'.format('knights', 'Ni') We are the knights who say "Ni!"
or am i missing something? Benjamin already replied to the other email, and I'm here just to reply also to this email.
Why do you think you have to explicitly state the position of the objects in the {} format? the numbers can be use to specify a position of the objects passed to the string, but if you want to print them as they are passed, there's no need to enumerate them.
Regards,
Hi Martin, thanks for your detailed email :) On Mon, Apr 11, 2011 at 22:03, Martin Feuchtwanger <martinf@underhill.ca> wrote:
Hi Sandro, Benjamin, et al.,
Maybe you didn't notice -- i was using 2.6.4
I thought I was using 2.6 but I was on a 2.7, that's the difference in behaviour :)
IDLE 2.6.4
print 'We are the {} who say "{}!"'.format('knights', 'Ni')
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> print 'We are the {} who say "{}!"'.format('knights', 'Ni') ValueError: zero length field name in format
As you already know, the tutorial is for python 2.7 so the syntax can be different than previous versions.
If you're wondering why i'm using 2.6... I was following the advice on http://wiki.python.org/moin/BeginnersGuide/Download so i downloaded and installed 2.6.4 on my windows work computer. I worked thru the web-based tutorial http://docs.python.org/tutorial/ and all was well until i got to the "knights of ni" example, hence my first email query.
Wikis are an extremely powerful tools, but they need to be updated - and reader should be aware (generally speaking) wiki can be outdated, while official documentation is not.
Interestingly, on the weekend, when i decided to install python on my home computer, i never saw any advice re stability on windows {i now realize it is because, silly me, i was getting advice on two different python.org web sites}, so i downloaded and installed 3.2 on it. Unfortunately, none of the print examples in the web-based tutorial http://docs.python.org/tutorial/ work on 3.2
Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
print 'We are the {} who say "{}!"'.format('knights', 'Ni') SyntaxError: invalid syntax
Now, i notice that the web tutorial is for python 2.7,
exactly that's the problem :)
and i'm well aware, from other parts of the web site, that there are significant changes from python 2 to python 3, and, yes, i know that in python 3 print follows strict function syntax, but may i suggest to you, and maybe to the entire docs/wiki team,
That each tutorial have this added at the beginning: "Note that this tutorial is version N and many of the examples will not work with version N-1 or version N+1 because the silly bunts at python.org like to invent a new kind of python with each release".
of course this won't happen. Please note that at the beginning of the tutorial, there's the precise version of it: in your case: Release: 2.7 Date: April 13, 2011
That you explain on both wiki.python.org and docs.python.org that, although they (docs and wiki) look the same they are different web sites and contain conflicting information.
Wiki.python.org is registration-free: you can create a user (or use an openid provider, like google) and start updating the pages you feel need a bit of attention. You'll convert your problematic experience in a contribution to python, and that would be awesome! Cheers, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
Sandro, Thanks for all the thoughtful responses -- most helpful! I still think that something like "Note that this tutorial is version N and many of the examples will not work with version N-1 or version N+1 because ..." Placed at the beginning --and frequently throughout-- will be very useful to a beginner --or anyone for that matter-- and it would even be more useful than "Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms." after all, it is supposed to be a tutorial on --not an advertisement for-- Python. Cheers, Martin Feuchtwanger On 13/04/2011 9:36 AM, Sandro Tosi wrote:
Hi Martin, thanks for your detailed email :)
On Mon, Apr 11, 2011 at 22:03, Martin Feuchtwanger<martinf@underhill.ca> wrote:
Hi Sandro, Benjamin, et al.,
Maybe you didn't notice -- i was using 2.6.4 I thought I was using 2.6 but I was on a 2.7, that's the difference in behaviour :)
IDLE 2.6.4
print 'We are the {} who say "{}!"'.format('knights', 'Ni') Traceback (most recent call last): File "<pyshell#0>", line 1, in<module> print 'We are the {} who say "{}!"'.format('knights', 'Ni') ValueError: zero length field name in format As you already know, the tutorial is for python 2.7 so the syntax can be different than previous versions.
If you're wondering why i'm using 2.6... I was following the advice on http://wiki.python.org/moin/BeginnersGuide/Download so i downloaded and installed 2.6.4 on my windows work computer. I worked thru the web-based tutorial http://docs.python.org/tutorial/ and all was well until i got to the "knights of ni" example, hence my first email query. Wikis are an extremely powerful tools, but they need to be updated - and reader should be aware (generally speaking) wiki can be outdated, while official documentation is not.
Interestingly, on the weekend, when i decided to install python on my home computer, i never saw any advice re stability on windows {i now realize it is because, silly me, i was getting advice on two different python.org web sites}, so i downloaded and installed 3.2 on it. Unfortunately, none of the print examples in the web-based tutorial http://docs.python.org/tutorial/ work on 3.2
Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
print 'We are the {} who say "{}!"'.format('knights', 'Ni') SyntaxError: invalid syntax
Now, i notice that the web tutorial is for python 2.7, exactly that's the problem :)
and i'm well aware, from other parts of the web site, that there are significant changes from python 2 to python 3, and, yes, i know that in python 3 print follows strict function syntax, but may i suggest to you, and maybe to the entire docs/wiki team,
That each tutorial have this added at the beginning: "Note that this tutorial is version N and many of the examples will not work with version N-1 or version N+1 because the silly bunts at python.org like to invent a new kind of python with each release". of course this won't happen. Please note that at the beginning of the tutorial, there's the precise version of it: in your case:
Release: 2.7 Date: April 13, 2011
That you explain on both wiki.python.org and docs.python.org that, although they (docs and wiki) look the same they are different web sites and contain conflicting information. Wiki.python.org is registration-free: you can create a user (or use an openid provider, like google) and start updating the pages you feel need a bit of attention. You'll convert your problematic experience in a contribution to python, and that would be awesome!
Cheers,
Hi Martin, About documentation links, see existing links to various version in the left sidebar of the main page http://docs.python.org/ and request for more links on http://bugs.python.org/issue8040 For a Python 3.2 tutorial, go to http://docs.python.org/py3k/tutorial/ Cheers
participants (3)
-
Martin Feuchtwanger
-
Sandro Tosi
-
Éric Araujo