fbpx

Porting Python 2 Laws to Python 3A¶

Porting Python 2 Laws to Python 3A¶

With Python 3 getting the future of Python while Python 2 remains in productive utilize, you should get venture designed for both significant releases of Python. This guide is supposed to let you figure out how far better help both Python 2 3 simultaneously.

If you are looking to port an extension component in the place of pure Python signal, please see Porting expansion Modules to Python 3 .

If you wish to learn one center Python designer’s accept why Python 3 had become, you can read Nick Coghlan’s Python 3 Q A or Brett Cannon’s Why Python 3 is present.

The small ExplanationA¶

Utilize Pylint to help make certain you don’t regress on your own Python 3 service ( python -m pip install pylint )

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

Once your dependencies are not any longer stopping your, use constant integration to make sure you remain suitable for Python 2 3 (tox often helps taste against multiple models of Python; python -m pip install tox )

Contemplate using optional static kind checking to be certain your kind consumption operates both in Python 2 3 (for example. incorporate mypy to check their typing under both Python 2 Python 3; python -m pip install mypy ).

Notice: utilizing python -m pip install ensures your pip your invoke is the one put in your Python currently being used, whether a system-wide pip or one setup within an online ecosystem .

DetailsA¶

A significant factor about promote Python 2 3 concurrently is that you can start nowadays! Although your dependencies aren’t supporting Python 3 yet that does not imply it’s not possible to modernize the laws now to guide Python 3. more adjustment required to support Python 3 trigger cleaner laws making use of newer methods in Python 2 rule.

Another heavily weighed is that modernizing the Python 2 rule to furthermore supporting Python 3 is essentially automatic individually. While you might need to make some API behavior due to Python 3 clarifying book data versus digital data, the lower-level work is now mainly done for you and thus can at least gain benefit from the automatic changes straight away.

Hold those tips planned even though you keep reading in regards to the information on porting the rule to compliment Python 2 3 at the same time.

Shed support for Python 2.6 and olderA¶

When you could make Python 2.5 assist Python 3, really much easier any time you simply assist Python 2.7. If falling Python 2.5 is not an option then the six project assists you to help Python 2.5 3 simultaneously ( python -m pip install six ). Create understand, however, that the majority of the works listed in this HOWTO will not be accessible to you.

If you are in a position to skip Python 2.5 and older, then requisite changes towards rule should always appearance like idiomatic Python code. At the worst you’ll have to need a features instead of a technique sometimes or need transfer a function versus utilizing an integrated one, but usually the entire transformation shouldn’t believe overseas to you.

But you should aim for just promote Python 2.7. Python 2.6 has stopped being freely recognized thereby isn’t receiving bugfixes. Meaning you will need to function around any issues you discover with Python 2.6. Additionally there are some resources discussed in this HOWTO that do not help Python 2.6 (age.g., Pylint), and this will become more commonplace as time goes by. It is going to merely end up being simpler for you in the event that you only offer the variations of Python that you must support.

Únete a la discusión

Comparar listados

Comparar
× ¿Necesitas ayuda?