Since Django doesn't yet support Python 3.x, I'm using Python 2.7. However, I'd like to go ahead and start familiarizing myself with the new Python 3.x syntax as much as possible. Which leads me to the question:
- What is the best way to write Python 2.7 code that will be as compatible as possible with Python 3.x?
I know that running python -3
will
Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.
However, I'm interested in getting used to Python 3.x syntax while still using Python 2.7.
For instance, it seems that I should be using the following imports to my code:
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
The above four __future__ import
statements are required as of Python 3.0, but not required in 2.7 as described in Python 2.7.3's documentation 27.11. Future Statement Definitions
What else?