In python 2.x, dividing two integers returns an integer. However, if you use
from ___future___ import division
you can get a float value:
>>> 3/2
1
>>> from __future__ import division
>>> 3/2
1.5
>>>
>>>
>>> 3//2
1
>>> 4/3
1.3333333333333333
>>>
After the import, you have to use // instead of / to do integer division. How can I revert the import so that / does integer division again?
__future__imports are special, and cannot be undone. You can read up on their behavior here.Here are a few relevant portions:
Since
__future__statements are handled at compile time as opposed to runtime, there is no runtime method for reverting the changed behavior.With normal modules you can remove or unimport the module by deleting whatever you imported from the namespace, and deleting the entry for that import in
sys.modules(this second part may not be necessary depending on the use case, all it does is force the reloading of the module if it is imported again).