Python 2 or 3

  • Thread starter Antti J Ylikoski
  • Start date
A

Antti J Ylikoski

I'm in the process of learning Python. I already can code
objet-oriented programs with the language. I have in my hands the
O'Reilly book by Mark Lutz, Programming Python, in two versions: the
2nd Edition, which covers Python 2, and the 4th edition, which covers
Python 3.

In the "official Python site" so to speak, http://www.python.org, it
is mentioned that the authors recommend the visitor, who is a novice,
to learn Python 2 rather than Python 3, because most of existing
software has been writen with Python 2.

The O'Reilly book has some 1200 pages. I would not want to invest
such an amount of work and time to an obsolete language (i. e. Python
2).

What is the opinion of the wizards here, shall I learm Python 2 or
Python 3? I'm posting this here because I feel that this point is
interesting to other students of Python.


Cheers, Antti "Andy" Ylikoski
Helsinki, Finland, the EU
 
G

Gnarlodious

If you are writing your own scripts, I would recommend Py3 for learning. But if you are studying existing scripts to learn, Py2 might be better.

I have been doing Python for about 2 years and started learning Py3 with noregrets. Py2 is not going to be "obsolete" for quite a while. It is almostall the same as Py3, just a few updates mostly of concern to those who maintain existing code. And actually, Python has been incrementally improved upon all along, just that Py3 was the cutoff point for stuff that HAD to change.

-- Gnarlie
 
A

Andrew Berg

What is the opinion of the wizards here, shall I learm Python 2 or
Python 3? I'm posting this here because I feel that this point is
interesting to other students of Python.
Unless you are tied to Python 2 in some way, go for Python 3 and don't
look back. There are a few major software projects that still do not
support Python 3 (more and more are getting ported or replaced as time
goes on), and many production systems are still using Python 2, but
don't let /potential/ roadblocks keep you away from Python 3. Another
thing to note is that, at least AFAICT, Jython, IronPython and PyPy are
not going to support Python 3 any time soon, so if you need to use one
of them, Python 2 is the way to go.
 
R

Roy Smith

Antti J Ylikoski said:
I have in my hands the O'Reilly book by Mark Lutz, Programming
Python, in two versions: the 2nd Edition, which covers Python 2, and
the 4th edition, which covers Python 3.

The engineer in me really has to wonder what the 3rd edition might have
covered :)
I would not want to invest such an amount of work and time to an
obsolete language (i. e. Python 2).

I think the best that can be said for Python 2 is, "It's not dead yet!".
The vast majority of production Python code written today is for 2.x,
for x in {5, 6, 7}. The biggest thing that's holding back adoption of 3
is that most of the major packages don't support 3 yet (but I saw an
announcement just this morning that django has been ported to 3).

I predict that 2012 will be the year of Python-3. I expect we're at the
point now that all major packages will either get ported to 3 in the
next year or two, or become abandonware. Also, people building new
packages will come out with versions for both 2 and 3 if they want their
stuff to get widely adopted.
What is the opinion of the wizards here, shall I learm Python 2 or
Python 3? I'm posting this here because I feel that this point is
interesting to other students of Python.

The difficult thing here is that you are living on the cusp. If you
came back and asked that question in a couple of years, I strongly
suspect the answer would be, "Don't bother with 2; 3 is what everybody
uses today". But, we're not there quite yet. Learn 2.
 
D

Dan Stromberg

I'm in the process of learning Python. I already can code
objet-oriented programs with the language. I have in my hands the
O'Reilly book by Mark Lutz, Programming Python, in two versions: the
2nd Edition, which covers Python 2, and the 4th edition, which covers
Python 3.

In the "official Python site" so to speak, http://www.python.org, it
is mentioned that the authors recommend the visitor, who is a novice,
to learn Python 2 rather than Python 3, because most of existing
software has been writen with Python 2.

The O'Reilly book has some 1200 pages. I would not want to invest
such an amount of work and time to an obsolete language (i. e. Python
2).

It mostly depends on what sort of thing you're learning Python for.

If you have a project in mind that has large dependencies that still
require Python 2.x, then you're probably best off with 2.x for now.

Otherwise, go with 3.x.

Or do what I've been enjoying: Install 2.x and 3.x, and test with
both, each step of the way. In this manner, you can pretty easily
write new code that runs on either equally well. But again, there's
the matter of dependencies.
 
A

Andrew Berg

PyPy has a roadmap for 3.2
http://pypy.org/py3donate.html
They definitely plan to do it one way or another.
I never said there were no plans, but at $2567 out of $60k, I don't see
it happening soon. Unless someone decides to donate a huge sum of money
or a large amount of code in the next couple months, I don't see a
release happening until at least the middle of next year. It would
definitely not be practical to learn Python 3 at this point if your
primary implementation is PyPy.
 
S

Steven D'Aprano

The O'Reilly book has some 1200 pages. I would not want to invest such
an amount of work and time to an obsolete language (i. e. Python 2).

Python 2 is not an obsolete language. The differences between Python 2
and Python 3 are minor, more like different dialects of one language than
two languages. I learned Python 1.5 and watched the extended transition
between 1.5 -> 2.2, and in my opinion, the 2.5 -> 3.2 transition is not
that much more difficult.

An experienced programmer won't have any difficulty learning both, and
swapping between them. Newbies who have never programmed before often
have trouble with the differences between 2.x and 3.x, but if you are an
experienced programmer, you shouldn't have any trouble at all. The
biggest difference to the language is that strings are now Unicode
instead of byte strings; this has forced a lot of English speakers to
learn about Unicode and bytes instead of assuming that the universe is
ASCII. Apart from that, the differences are, in my opinion, trivial.

However, there are a lot of them:

http://docs.python.org/release/3.0.1/whatsnew/3.0.html


But the most important ones in my opinion are:

* unicode text, as mentioned above, and the consequences of this;

* some of the modules in the standard library have been renamed;

* various new modules have been added;

* some built-in functions and methods which used to return lists now
return lazy iterators or views;

* print is now a function instead of a statement;

* a small number of syntax changes, some of which are also supported by
Python 2.6 and 2.7;

* "classic classes" no longer exist, so there is now only one class
mechanism, not two.

If you can deal with the difference between these two lines without
getting confused:

print md5.md5("spam").hexdigest() # Python 2.x
print(hashlib.md5("spam").hexdigest()) # Python 3.x

you're half way there.
 
C

Chris Angelico

If you can deal with the difference between these two lines without
getting confused:

print md5.md5("spam").hexdigest()  # Python 2.x
print(hashlib.md5("spam").hexdigest())  # Python 3.x

The second line needs to be:
print(hashlib.md5("spam".encode()).hexdigest())

Relatively insignificant differences, since Python 2 and Python 3 both
support both bytes and unicode strings. The only difference is that
Py3 makes Unicode the default, forcing you to be explicit when you
want bytes.

ChrisA
 
A

Arnaud Delobelle

I'm in the process of learning Python.  I already can code
objet-oriented programs with the language.  I have in my hands the
O'Reilly book by Mark Lutz, Programming Python, in two versions: the
2nd Edition, which covers Python 2, and the 4th edition, which covers
Python 3.

In the "official Python site" so to speak, http://www.python.org, it
is mentioned that the authors recommend the visitor, who is a novice,
to learn Python 2 rather than Python 3, because most of existing
software has been writen with Python 2.

The O'Reilly book has some 1200 pages.  I would not want to invest
such an amount of work and time to an obsolete language (i. e. Python
2).

Python 2 and Python 3 are mostly the same language. Learning either
will be equally valuable IMHO. There are some significant differences
but if you have a good understanding of one, you will have no problem
adapting very quickly to the other.

And Python 2 is definitely not obsolete :)
 
G

Gelonida N

I'm in the process of learning Python. I already can code
objet-oriented programs with the language. I have in my hands the
O'Reilly book by Mark Lutz, Programming Python, in two versions: the
2nd Edition, which covers Python 2, and the 4th edition, which covers
Python 3.

In the "official Python site" so to speak, http://www.python.org, it
is mentioned that the authors recommend the visitor, who is a novice,
to learn Python 2 rather than Python 3, because most of existing
software has been writen with Python 2.

The O'Reilly book has some 1200 pages. I would not want to invest
such an amount of work and time to an obsolete language (i. e. Python
2).

What is the opinion of the wizards here, shall I learm Python 2 or
Python 3? I'm posting this here because I feel that this point is
interesting to other students of Python.


Cheers, Antti "Andy" Ylikoski
Helsinki, Finland, the EU

I would still stick with python 2.

In my opinion there is no reason to rush to the most recent version.

Especially when working in a corporate environment or when being obliged
to use certain web servers / servers you will notice, that
you will still encounter quite some hosts with python 2.5 and even some
with python2.4.

Most machines, that I have to use, run python 2.6 (and some python
2.5) I personally try to write most of my code such that it could still
run with python 2.5 I decided that python2.4 is my cut-off point,
though I still have one machines and some embedded devices, which just
run 2.4


Other considerations

- there are still more libraries / packages available for python
2 than for python 3, though this is changing.

- if you write code nicely enough in python 2, then you can translate it
to python 3. autmatically. However up to my knowledge you
cannot automatically translate python 3 code to python 2 code.

With that strategy your code will be able to run on most web servers and
your own machines.



If you want to write your own code which does not have to run on other
machines and / or if you want to heavily use unicode, then it might be
better to start with Python 3.
 
C

Chris Angelico

if you write code nicely enough in python 2, then you can translate it
 to python 3. autmatically.

It's entirely possible to write code that can run on both Python 2 and
Python 3 - at least, if you can target 2.6/2.7 and get the
appropriate future directives. Add in a few exception-guarded imports
for the renamed modules, and then all you're left with is a few things
where you can take a little care while coding, run it through both
versions to test, and have it all work.

ChrisA
 
T

Terry Reedy

I would still stick with python 2.

In my opinion there is no reason to rush to the most recent version.

Python 3 is 3 years old. Starting with it now is hardly rushing.
There are several reasons someone 'in the process of learning Python'
might want to start with it. The removal of old stuff makes it more
steamlined and easier to learn. There is only one class system instead
of two, one meaning of '/' instead of two, and one version of the input,
range, map, and filter functions instead of two. For anyone working with
unicode instead of ascii, Python 3 is much better, and 3.3 will be
better yet. There are numerous improvements to the standard library.
Most but not all bugfixes have been backported; changes and new features
have not.

What's New in 3.0/1/2 is a long list of possible reasons.
 
C

Chris Angelico

For anyone working with unicode instead of ascii...

Which, frankly, should be everyone. You can't get away with assuming
that a character is a byte any more; even if you stick to the US,
you're going to run into some non-ASCII symbols sooner or later. Of
course, you can work with UTF-8, which means that anything that fits
into 7-bit ASCII will be represented as itself; but you still need to
be aware of the difference between 'bytes' and 'str' (or between 'str'
and 'unicode').

ChrisA
 
Z

Zaphod

I'm in the process of learning Python. I already can code
objet-oriented programs with the language. I have in my hands the
O'Reilly book by Mark Lutz, Programming Python, in two versions: the 2nd
Edition, which covers Python 2, and the 4th edition, which covers Python
3.

It doesn't matter that much which one you learn. The differences aren't
that big between the two. You could easily use the 2nd edition but use
python 3 and the biggest difference you will find is between print
"stuff" vs print("stuff"). In fact, doing it this way will make you a
better programmer.

Cheers, Antti "Andy" Ylikoski
Helsinki, Finland, the EU

ps: I quite like your Finnish "Dudesons" program. They remind me of some
of the rednecks I grew up with here on Vancouver Island (British
Columbia, Canada)
 
T

Tobiah

What is the opinion of the wizards here, shall I learm Python 2 or
Python 3? I'm posting this here because I feel that this point is
interesting to other students of Python.

Use the newer version and don't look back.
 
E

Enrico 'Henryx' Bianchi

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Use the newer version and don't look back.

Interesting reply, but if I have a platform wich doesn't support Python 3
(e.g. RHEL 5.x)? ]:)

Enrico
P.S. note that: I *don't* want to recompile Python in production environment
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQEcBAEBAgAGBQJO4pbOAAoJED3SMOGZLYdYQ7sIAI3vfvOyQc5Gx205cDMS7bPK
uXxZI7ShqybyEv0NMDapxURQhz59Kc9zh8E/OKDiXohjmkE1YA78K7qSKyrtXTMy
ppcGUU5USaQhPZ+RqOEj95aTxQj3CW/8w74rNEirIMn6+yGt4QjWRuGT1K6aUM51
BXF9I22f37z/sJ7x+fZUL9R7G1HA4saRGEiQGxBgkmt6gi28nboOibdxfw9bmP5x
aHbpVYQ6yo+7nOf0XZno/pl0zkpDvhS/tNvvuH8kYQIvMLyQZ/f+xZJ6yj58S5Se
AGSGXEDRemw0Ge83HjJvmQE3JXjy1fc1gCQSnmqQifXW7h18q99L3okJds+uHnE=
=PwK5
-----END PGP SIGNATURE-----
 
S

Steven D'Aprano

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Use the newer version and don't look back.

Interesting reply, but if I have a platform wich doesn't support Python
3 (e.g. RHEL 5.x)? ]:)

RHEL supports Python 3, it just doesn't provide Python 3. It almost
certainly will work if you install from source. I haven't tried it on
RHEL myself, but I have done so on Fedora and Centos, and there's no
problem.

But be warned that you should not replace the system python with Python
3. When installing, don't use "make install", as that will replace the
system Python, instead use "make altinstall". Then the command "python"
will still refer to the system Python (probably Python 2.4 or 2.5?), and
"python3" should refer to Python 3.x.

Enrico
P.S. note that: I *don't* want to recompile Python in production
environment

You shouldn't be learning programming on a production server :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top