Porting Python 2 Rule to Python 3A¶

With Python 3 being the continuing future of Python while Python 2 still is in productive need, you should get task designed for both major secretes of Python. This informative guide is supposed to make it easier to figure out how better to support both Python 2 3 concurrently.

If you are searching to port an expansion module rather than pure Python signal, be sure to read Porting Extension segments to Python 3 .

If you would like to read through one core Python developer’s deal with why Python 3 had become, look for Nick Coghlan’s Python 3 Q A or Brett canon’s Why Python 3 prevails.

The light ExplanationA¶

Need Pylint to make certain you do not regress in your Python 3 support ( python -m pip install pylint )

Usage caniusepython3 to discover which of the dependencies tend to be preventing your using Python 3 ( python -m pip install caniusepython3 )

When your dependencies are no lengthier stopping you, use continuous integration to ensure that you remain appropriate for Python 2 3 (tox will experiment against several versions of Python; python -m pip install tox )

Consider utilizing elective fixed means examining to be sure their kind consumption operates in Python 2 3 (e.g. need mypy to evaluate your own keying in under both Python 2 Python 3; python -m pip install mypy ).

Notice: making use of python -m pip install guarantees that the pip you invoke could be the one installed your Python presently in use, whether a system-wide pip or one setup within a virtual environment .

DetailsA¶

An important facet about support Python 2 3 at the same time is you can begin nowadays! In the event the dependencies are not supporting Python 3 yet that doesn’t indicate you cannot modernize the laws now to support Python 3. more adjustment necessary to supporting Python 3 lead to cleaner rule making use of newer tactics despite Python 2 code.

Another key point is the fact that modernizing the Python 2 signal to additionally help Python 3 is essentially computerized for your family. Even if you need to make some API choices using Python 3 clarifying text facts versus digital information, the lower-level tasks are today primarily done for both you and thus can at the least gain benefit from the automatic adjustment straight away.

Hold those key points in your mind although you keep reading regarding the specifics of porting the code to aid Python 2 3 at the same time.

Decrease help for Python 2.6 and olderA¶

Although you makes Python 2.5 utilize Python 3, it’s easier if you simply utilize Python 2.7. If dropping Python 2.5 just isn’t an option then the six project assists you to supporting Python 2.5 3 at the same time ( python -m pip install six ). Do recognize, though, that nearly all the jobs listed in this HOWTO are not available to you.

If you find yourself capable miss Python 2.5 and more mature, then the necessary improvement towards rule should consistently feel and look like idiomatic Python code. At worst you are going to need to utilize a purpose instead of a method sometimes or must import a function in place of utilizing an integral one, but or else the overall transformation should not think overseas to you personally.

Nevertheless should shoot for merely promoting Python 2.7. Python 2.6 no longer is freely supported and therefore just isn’t obtaining bugfixes. Meaning you will need to operate around any problems you find with Python 2.6. There are some equipment mentioned contained in this HOWTO which do not supporting Python 2.6 (elizabeth.g., Pylint), which will be much more commonplace as time goes on. It will merely end up being simpler for you should you decide merely offer the live chat room online moldova models of Python you have to supporting.

Leave a Reply


Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.

ACEPTAR