Which Python 2.7 or 3.x?


20 posts
by Clifford » Fri May 04, 2012 5:58 pm
My question is what version of Python will be the preferred or de facto teaching and development language for Raspberry Pi?

This arises from my attempt to find a beginner guide for Python (ideally a paper book), one suitable for and interesting enough for kids.  Although a professional software developer myself, I am not familiar Python, so I did a little research.  An issue that I came across is that the latest Python 3.x specification of the language has syntax changes that renders 2.x code no longer valid in a Python 3.x interpreter.  However 2.7 appears to be the currently favoured version - presumably with practitioners reluctant to migrate existing code-bases and libraries until 3.x reaches critical mass.  Also much of the available literature is still 2.x based - especially that aimed at kids.

I could see it become confusing and dispiriting to children if they are taught 2.7 only to find that later, their existing code refuses to run because the hard-learned syntax changed underneath their feet!  All our "Hey kids this is fun" won't make the migration seem any less tedious and unnecessary, and may put some off before they realise their potential. On the other hand if existing resources and libraries are 2.x based, the greatest scope for development may still lie with 2.7.  But when 2.7 finally withers on the vine due to lack of continued development, an otherwise unnecessary migration to 3.x or later must at some point occur.

All this confusion at this time I might suggest would make Python particularly unsuitable as a teaching language.  I might be teaching my kids C++!
Posts: 30
Joined: Fri May 04, 2012 3:19 pm
by croston » Fri May 04, 2012 6:15 pm
The educational release will be using Python 3
User avatar
Posts: 420
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
by Clifford » Fri May 04, 2012 6:21 pm
Thanks.  Now I know that, any recommendations on the book I am looking for?  The obvious "for kids" or "beginners" titles on Amazon are not currently written to 3.x.
Posts: 30
Joined: Fri May 04, 2012 3:19 pm
by croston » Fri May 04, 2012 6:51 pm
http://inventwithpython.com/ is aimed at youngsters, uses Python 3 and looks quite good.

Bear in mind that the difference between Python 2 and Python 3 is minimal.
User avatar
Posts: 420
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
by prodata » Fri May 04, 2012 7:21 pm
I dare say you're aware already, but Amazon isn't necessarily the best or cheapest source of computer books. One UK source I often use is:

http://www.compman.co.uk

who will quite often have stock when Amazon doesn't (Amazon don''t seem to like stocking more than the odd copy of low volume sellers) and I'm sure there are other comparable online outlets.
Posts: 113
Joined: Tue Jan 24, 2012 5:53 pm
by Clifford » Sat May 05, 2012 8:18 am
croston said:


Bear in mind that the difference between Python 2 and Python 3 is minimal.



I am aware of that, but even those slight differences might cause confusion and discouragement in an 8 year old, and would certainly impede independent learning.  I have seen older students struggle to get over the reasons why the C or C++ they were taught on some ancient compiler and out-of-date course text that their college used fail to work in the real world.

prodata said:

Amazon don"'t seem to like stocking more than the odd copy of low volume sellers[...]

I suspect I am not looking for a low volume seller, but rather one that many have had success with.  Understand that I am not the intended audience for this book.
Posts: 30
Joined: Fri May 04, 2012 3:19 pm
by Clifford » Sat May 05, 2012 8:21 am
croston said:


http://inventwithpython.com/ is aimed at youngsters, uses Python 3 and looks quite good.


... and emphasises games writing.  I am not averse to learning through such method, by as a real-time embedded systems engineer, my heart sinks when games are seen or encouraged to be seen as the primary purpose of computing technology.
Posts: 30
Joined: Fri May 04, 2012 3:19 pm
by prodata » Sat May 05, 2012 9:08 am
I know this isn't specifically an 'educational' comment but since this thread has started here...

What about the question of Py2K vs Py3K for non-educational applications? Anyone care to venture an opinion please?

It's understood that the original stimulus for RPi was for education-related uses, but the board has obviously generated a lot of interest for other categories of use such as home-brew embedded projects. These might well involve the use of Python libraries and eg GUI toolkits such as wxPython. A cursory look suggests that many of these extension libraries are not immediately compatible with Py3K. So wouldn't the safest thing be to stick with Python 2.x?
Posts: 113
Joined: Tue Jan 24, 2012 5:53 pm
by rurwin » Sat May 05, 2012 9:23 am
It is possible to use 2.x with 3.x syntax. Put this as the first line of your program, write the rest as if you were using 3.x, and you can run it under either 2.x or 3.x
from __future__ import absolute_import, division, generators, unicode_literals, print_function, nested_scopes, with_statement

I don"t know how perfect it is, but I haven"t found a problem yet.
User avatar
Moderator
Moderator
Posts: 2890
Joined: Mon Jan 09, 2012 3:16 pm
by Clifford » Sat May 05, 2012 9:35 am
rurwin said:


Put this as the first line of your program,[...]


Just the sort of arcane "magic incantation" one would want to avoid when teaching kids.  Which was kind of my point - stability and consistency are key.
Posts: 30
Joined: Fri May 04, 2012 3:19 pm
by Clifford » Sat May 05, 2012 10:43 am
croston said:


http://inventwithpython.com/ is aimed at youngsters, uses Python 3 and looks quite good.

Bear in mind that the difference between Python 2 and Python 3 is minimal.



OK, I took a look and ordered paper copies.  Note the the text explicitly says


Important Note! Be sure to install Python 3, and not Python 2. The programs in this book use Python 3, and you'll get errors if you try to run them with Python 2.


so the author is very clear about that.  I was somewhat disappointed with the inclusion of the "Dinosaur Comic", in the introduction, it includes some colourful language not really suitable for the younger end of the intended readership, and in any case is unnecessary and gratuitous.
Posts: 30
Joined: Fri May 04, 2012 3:19 pm
by Stateside » Sun May 13, 2012 12:29 pm
"Snake Wrangling for Kids" is a printable electronic book, for children 8 years and older, who would like to learn computer programming. It covers the very basics of programming, and uses the Python 3 programming language to teach the concepts. -and it is free.

http://www.briggs.net.nz/snake-wrangling-for-kids.html
Posts: 67
Joined: Sun May 13, 2012 12:26 pm
by Stateside » Sun May 13, 2012 6:13 pm
Hello World!
Computer Programming for Kids and Other Beginners
Warren D. Sande and Carter Sande
This book teaches programming using a computer language called Python
http://www.manning.com/sande/
http://www.manning.com/sande/excerpt_contents.html

Video Material :
Tutorials by Elementary School student Carter Sande

Randomness in Python
http://www.youtube.com/watch?v=_C6_QjRgCPE

Python Functions
http://www.youtube.com/watch?v=2EaWkk8qS9g

How to make a simple bouncing ball using a 3D graphics module for Python called VPython.
http://www.youtube.com/watch?v=ydrNETZkfkw

Q. What is PythonCard?
PythonCard is designed to allow you to quickly and easily design and build fully functioning applications with a graphical user interface.
Q. What do I need to use PythonCard?
A. Python 2.3 or higher and wxPython 2.5.2.8 or higher.
http://www.youtube.com/watch?v=HCUlkJjF ... 0FAD3A8C73
Posts: 67
Joined: Sun May 13, 2012 12:26 pm
by Stateside » Sun May 13, 2012 7:08 pm
Python Programming for the Absolute Beginner, 3rd Edition
Michael Dawson
Python 3 x
If you are new to programming with Python and are looking for a solid introduction, this is the book for you. Developed by computer science instructors, books in the "for the absolute beginner" series teach the principles of programming through simple game creation.

Has good reviews on book seller sites.
For real world experience you can ask:

viewtopic.php?f=2&t=319&p=73429

I'm learning Python from 'Python Programming - for the absolute beginner - 3rd edition'. I find it a great guide, easy to follow and covers the basics.

To get to the introduction, i'm FullXion, and my real name is Bilal. I was born and live in Rotherham, UK and i'm 15, soon to be 16.
Posts: 67
Joined: Sun May 13, 2012 12:26 pm
by RaspberryPie » Tue May 22, 2012 8:22 pm
just ordered this from amazon...now which shows up first, my pi or my python? :D
A Raspberry a Day
Keep the Student at Play
So Get Your Slice of Pi
Let your programming Fly
User avatar
Posts: 20
Joined: Thu Apr 26, 2012 3:49 pm
Location: florida
by RaspberryPie » Tue May 22, 2012 8:24 pm
rurwin wrote:It is possible to use 2.x with 3.x syntax. Put this as the first line of your program, write the rest as if you were using 3.x, and you can run it under either 2.x or 3.xfrom __future__ import absolute_import, division, generators, unicode_literals, print_function, nested_scopes, with_statement
I don"t know how perfect it is, but I haven"t found a problem yet.

apparently +1 for this, leaves it open to the developer..
A Raspberry a Day
Keep the Student at Play
So Get Your Slice of Pi
Let your programming Fly
User avatar
Posts: 20
Joined: Thu Apr 26, 2012 3:49 pm
Location: florida
by rurwin » Tue May 22, 2012 8:39 pm
Clifford wrote:
rurwin wrote:Put this as the first line of your program,

Just the sort of arcane "magic incantation" one would want to avoid when teaching kids.  Which was kind of my point - stability and consistency are key.

It has been said before, by me and others, that for teaching purposes you should use Python 3. That will be the standard within one or two years. Right now you can't use Python 3 for everything since several major libraries have not been ported. However if in your personal projects you need to use a library that is only available in Python 2, then you can include that line and continue writing as if you were using Python 3. So you don't have to remember two different syntaxes and behaviours.

Similarly, if you write a program for others to use, then you can include that line and everyone can use your program whether they are using Python 2 or Python 3.

So yes it is a magic incantation and I probably would seek to avoid it in a teaching situation, but it enhances stability and consistency.
User avatar
Moderator
Moderator
Posts: 2890
Joined: Mon Jan 09, 2012 3:16 pm
by fromagique » Tue May 22, 2012 10:34 pm
I think that the differences between 2.x and 3.x are not big enough to worry about from a teaching perspective. You could teach either one and by the time the kids are advanced enough to use things that would make a difference, they'll be OK with learning there's a difference. The language, even with the differences, is far easier than learning C++.
Posts: 31
Joined: Tue May 22, 2012 4:41 am
by mkeeley » Tue May 29, 2012 5:39 pm
When I was deciding a while back the consensus was to stick with v2, especially true when you start looking for libraries and find many don't (yet) support v3.
Posts: 29
Joined: Sun Feb 19, 2012 12:44 am
by antiloquax » Sun Jun 03, 2012 5:53 am
Stateside wrote:Python Programming for the Absolute Beginner, 3rd Edition
Michael Dawson
Python 3 x
If you are new to programming with Python and are looking for a solid introduction, this is the book for you. Developed by computer science instructors, books in the "for the absolute beginner" series teach the principles of programming through simple game creation.

Yes, I agree. This is a good book.
I also really like the material on this website:Professor Craven's Pythong Tutorial
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am