After reading on the web, I noticed that there was a promise made that Python 2.7 would use absolute imports as the default. However it seems it is not the case, and that we still have to use
from __future__ import absolute_import
I don't want my code to use some legacy settings, so I want to make sure all the modules have this enabled. How to do that, without having to repeat this statement in every single module?
from __future__
imports must be done first, and are module specific. There is no easy way to have it in effect for all your modules without actually having the line be in all your modules.
I believe you can use grep
(if not, roll your own) to tell you which of your modules do not have that line in them.
If you want to do it the hard way, take a look at either importlib
, or replacing __import__
. Using either of these two methods you could open the .py
file, insert the
from __future__ import absolute_import
line (if not already there), and then do the actual import. Take care that you don't add that line to other modules besides your own, however, as you will undoubtedly get errors from modules expecting the relative import semantics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With