tags:

views:

325

answers:

4

If I learn python 3.0 and code in it, will my code be still compatible with Python 2.6 (or 2.5 too!)?


Remarkably similar to:

If I'm Going to Learn Python, Should I Learn 2.x or Just Jump Into 3.0?

+5  A: 

No, 3.x is largely incompatible with 2.x (that was actually a major motivation for doing it). In fact, you probably shouldn't be using 3.0 at all-- it's rather unusable at the moment, and is still mostly intended for library developers to port to it so that it can be usable.

Devin Jeanpierre
"it's rather unusable" doesn't accurately describe it
fuentesjr
Alright, let me word it more accurately. It has very few third-party APIs, which are necessary for many tasks, and the API is rapidly-changing. Things that would ordinarily take several subversions are changed in a single bugfix release-- in 3.0.1, cmp() was removed. It's not ready yet.
Devin Jeanpierre
+1  A: 

NO. Python 3 code is backwards incompatible with 2.6. I recommend to begin with 2.6, because your code will be more useful.

Sergei
By what time Python 3.0 will be useful to some extent?
Xolve
hard to say. 2.x codebase just too huge. it's like Perl 6 :-) MAYBE it will be widely used in 5 years from now.
Sergei
+2  A: 

Python 2.6 and Python 3.0 are very compatible with each other. There honestly aren't very many differences between the two. At this point, third-party library support is far better for the 2.x series (last I checked, a few libraries I use hadn't been updated from 2.5, but going from 2.5 to 2.6 is just a recompile, but 2.6 to 3.0 for C-level stuff is a real pain).

Just start learning 2.6. The infrastructure is there now, and there's plenty of help for when you finally want to move to 3.x. 2.x is not going away: there will be a 2.7 release at some point, so you're not going to be out of luck if you learn 2.6 now.

kquinn
How is 2.6 and 3.0 compatible? Do you mean "After running the converter, the resulting code will generally work in 3.0?"Hint: Even the 'print' statement is incompatible.
Arafangion
A few different language constructs here and there aren't a huge deal if you're learning.
Dana the Sane
`print x` versus `print(x)` is really the biggest user-visible change! Okay, so strings are full Unicode by default; that's fine, there's a __future__ import for Py3k literals in 2.6. And a few things that are lists in 2.6 are iterators in 3.0. Not earth-shattering differences for a human mind.
kquinn
+1  A: 

It would be easier to use 2.6 right now because most external libraries are not compatible with 3 yet.

jle