Porting Python 2 Signal to Python 3A¶
With Python 3 are the future of Python while Python 2 continues to be in energetic need, it is good to get project available for both biggest secretes of Python. This guide is supposed to make it easier to work out how far better supporting both Python 2 3 simultaneously.
If you are looking to port an expansion component versus pure Python signal, be sure to read Porting expansion segments to Python 3 .
If you want to see one center Python developer’s take on the reason why Python 3 has been around since, you can read Nick Coghlan’s Python 3 Q A or Brett canon’s Why Python 3 is available.
The brief ExplanationA¶
Need Pylint to make yes that you don’t regress in your Python 3 help ( python -m pip install pylint )
Utilize caniusepython3 to learn which of your dependencies include preventing the using Python 3 ( python -m pip install caniusepython3 )
Once your dependencies are not any lengthier blocking your, use constant integration to make sure you stay compatible with Python 2 3 (tox can help testing against http://www.datingmentor.org/local-hookup/wichita-falls numerous forms of Python; python -m pip install tox )
Contemplate using recommended static type checking to make certain their means use works both in Python 2 3 (for example. use mypy to check on your own keying in under both Python 2 Python 3; python -m pip install mypy ).
Mention: making use of python -m pip install assurances the pip you invoke may be the one setup for the Python currently being used, whether it be a system-wide pip or one setup within an online surroundings .
DetailsA¶
An important factor about supporting Python 2 3 concurrently is that you could begin nowadays! Regardless of if their dependencies aren’t promoting Python 3 yet that will not indicate you cannot modernize their code now to support Python 3. Most modifications needed to support Python 3 trigger cleaner laws using new practices in Python 2 code.
Another heavily weighed is that modernizing their Python 2 code to in addition help Python 3 is largely automatic for your needs. However need to make some API choices courtesy Python 3 clarifying text data versus binary data, the lower-level work is today primarily completed for both you and hence can no less than gain benefit from the automated improvement instantly.
Keep those tips at heart when you keep reading towards information on porting the laws to support Python 2 3 at the same time.
Shed help for Python 2.6 and olderA¶
While you will make Python 2.5 assist Python 3, really easier if you only have to utilize Python 2.7. If shedding Python 2.5 just isn’t an alternative then your six project assists you to supporting Python 2.5 3 concurrently ( python -m pip install six ). Manage see, however, that most the jobs listed in this HOWTO will never be accessible to you.
If you are able to skip Python 2.5 and earlier, then your necessary changes your code should still overall look and feeling like idiomatic Python code. At worst you will need to utilize a function versus a way sometimes or must transfer a function in the place of utilizing a built-in one, but otherwise all round transformation shouldn’t feeling foreign for your requirements.
You should try to get just promoting Python 2.7. Python 2.6 no longer is freely supported and therefore isn’t getting bugfixes. This implies you will have to run around any issues you find with Python 2.6. Additionally there are some tools pointed out inside HOWTO that do not help Python 2.6 (elizabeth.g., Pylint), and this will become more commonplace in the future. It will just getting easier for you should you decide best offer the variations of Python you have to support.