Page 1 of 1

Python3 vs. Python

Posted: Tue Jan 28, 2014 4:52 am
by RCobbTX
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.

Re: Python3 vs. Python

Posted: Tue Jan 28, 2014 5:21 am
by AndyD
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.

Re: Python3 vs. Python

Posted: Tue Jan 28, 2014 6:39 am
by gkreidl
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.

Re: Python3 vs. Python

Posted: Tue Jan 28, 2014 6:41 am
by smithg400
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.

Re: Python3 vs. Python

Posted: Tue Jan 28, 2014 8:58 am
by DougieLawson
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.