Can a single Python project use 2.x and 3.x code?

I am going to start on a long (~ 1 year) Python programming project. 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 3.x syntax).

Is there any way for me to create a project that will mix 2.x and 3.x modules? Or should I just bite the bullet and use either 2.x (preferable since I really want to learn wxPython) or 3.x?

Thanks,

Mike

+4
source share
3 answers

Python 2 and 3 are no different. If you have studied Python 2 well, you will be interested in reading Python 3. The official recommendation says that you should use Python 2.6 (current version) and try to be advanced. Python 3 is currently not an option for large projects, since virtually none of the popular packages have yet been translated. But the development of Python 2 and 3 will continue in parallel for a long time, so you will not lose much without using Python 3. You can import many syntax functions 3 (string literals, division, print Unicode, absolute import) using the __future__ module, and the standard the library remains basically the same. Therefore, I would recommend using Python 2.

+3
source

You should use python 2.7 (it is expected that a release is expected in the coming days), which is very close to python 3.1 and the code does not care about using legacy functions. There is the latest version of wxpython for python 2.7. After wxpython receives 3.1-3.2 builds, code conversion should not be too painful. However, wxpython has a final transition term :-(

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

+5
source

mixing wxPython (2.x) + usage with learning new syntax (3.x)

Do not mix.

Burn Python 2. Get it working.

Play with Python 3 separately. Do not mix.

When various packages and modules are available in Python 3, use the 2to3 transform to create Python 3. You will find some minor issues. Fix your Python 2 so that your package works in Python 2 and also works after the conversion.

Then you can give up support for Python 2 and focus on Python 3.

Do not mix.

+2
source

Source: https://habr.com/ru/post/1311541/


All Articles