RCobbTX
Posts: 10
Joined: Thu Jan 09, 2014 1:08 pm

Python3 vs. Python

Tue Jan 28, 2014 4:52 am

I have both Python and Python3. Where can I read up on the differences. This Pi learning curve is pretty steep, do I really need both? The simple Print command - print "hello" - throws an error on Python3.

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Python3 vs. Python

Tue Jan 28, 2014 5:21 am

RCobbTX wrote:I have both Python and Python3. Where can I read up on the differences. This Pi learning curve is pretty steep, do I really need both? The simple Print command - print "hello" - throws an error on Python3.
I am not a python developer however. To print in python 3 you need to use brackets.

Code: Select all

print("hello")
Start looking here. Also, what's new in Python 3.0.

gkreidl
Posts: 6326
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Python3 vs. Python

Tue Jan 28, 2014 6:39 am

RCobbTX wrote:I have both Python and Python3. Where can I read up on the differences. This Pi learning curve is pretty steep, do I really need both? The simple Print command - print "hello" - throws an error on Python3.
You don't need both of them, but the operating system does, as it contains quite a number of python (2.x) scripts. If you are a beginner, you should start directly with Python3.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

smithg400
Posts: 148
Joined: Sat Dec 24, 2011 3:37 pm

Re: Python3 vs. Python

Tue Jan 28, 2014 6:41 am

There were substantial changes introduced in python3 which meant that most of the code previously developed for python2 no longer works with version 3. Generally the changes that need to be made are quite small (like the need for brackets), but they take time to implement and there is still lots of code that only works with python2.

So, if you are writing code yourself, it is a good idea to use python3, however if you want to download some python code and use it, you need to check if it is designed for python2 or python3 and use the appropriate version. The exception to this is if you want to write your own code but make use of a library that someone else has written, if the library hasn't been ported to python3 then you'll need to use python2 yourself.

As RCobbTX says some of the code in the operating system itself is written in python2 and some in python3 - so you need both installed.

Hope this helps explain the reason for the two versions.

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Python3 vs. Python

Tue Jan 28, 2014 8:58 am

smithg400 wrote:There were substantial changes introduced in python3 which meant that most of the code previously developed for python2 no longer works with version 3. Generally the changes that need to be made are quite small (like the need for brackets), but they take time to implement and there is still lots of code that only works with python2.
And there is the reason why python 2 will never die.

It's the second most stupid thing about python after the semantic white space.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Beginners”