0

I am interested in understanding the purpose of the following pieces of code:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

I have read up from the manual and other articles that this is the purpose: https://docs.python.org/3/library/future.html

I am not sure I am interpreting this correctly. Hence I'm wondering if futures is to make the code 'future-proof', i.e Python 2 and Python 3 applicable. If this is the right understanding, should I be doing this in all my code from now on?

Thanks!

deceze
  • 491,798
  • 79
  • 706
  • 853
VK1
  • 171
  • 1
  • 1
  • 8
  • all your code from now on should really be written in python 3 if possible so this is unnecessary – Sayse Jan 29 '20 at 13:27
  • 1
    @Sayse Those particular futures, yes, but the future doesn't stop coming; e.g. `from __future__ import annotations`… – deceze Jan 29 '20 at 13:28
  • @deceze Till date I have never used the from __futures__ import print. But my code will still print when I say print(''..."). Hence, I don't follow why we use it. – VK1 Jan 29 '20 at 13:30
  • See https://stackoverflow.com/a/33996938/476. – deceze Jan 29 '20 at 13:31
  • @deceze cool - makes sense! Thanks – VK1 Jan 29 '20 at 13:38

0 Answers0