Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one Python project use both 2.x and 3.x code?

I'm going to start on a long (~1-year) programming project in Python. I want to use wxPython for my GUI (supports 2.6), but I also want to use 3.1 for the rest of the project (to start using the 3.x syntax).

Is there any way for me to design a project that mixes 2.x and 3.x modules? Or should I just bite the bullet and use either 2.x (preferred, since I really want to learn wxPython) or 3.x throughout?

Thanks,

Mike

like image 945
MikeRand Avatar asked Jun 01 '10 17:06

MikeRand


People also ask

Can you mix Python 2 and 3?

Don't "mix". When the various packages and modules are available in Python 3, use the 2to3 conversion to create Python 3. You'll find some small problems. Fix your Python 2 so that your package works in Python 2 and also works after the conversion.

Are all Python version 2 x programs compatible with Python 3 x?

A lot of libraries of Python 2 are not forward compatible. A lot of libraries are created in Python 3 to be strictly used with Python 3. Python 2 is no longer in use since 2020. Python 3 is more popular than Python 2 and is still in use in today's times.

Does code Python 2 work with Python 3?

Python version 3 is not backwardly compatible with Python 2. Many recent developers are creating libraries which you can only use with Python 3. Many older libraries created for Python 2 is not forward-compatible.

Can a program written in Python 2 run in Python 3 can a program written using Python 3 run in Python 2?

Python 2.6 includes many capabilities that make it easier to write code that works on both 2.6 and 3. As a result, you can program in Python 2 but using certain Python 3 extensions... and the resulting code works on both.


1 Answers

You should use python 2.7 (a release candidate is expected in the next days) that is very close to python 3.1 and to code taking care of no using deprecated features. There is a recent version of wxpython for python 2.7. After wxpython gets 3.1-3.2 builds, conversion of the code should not be too hurting. Still, wxpython has no deadline for the transition :-(

Another option is to use pyQt that already has builds for python 3.1

like image 153
joaquin Avatar answered Sep 30 '22 02:09

joaquin