As I'm getting further into TensorFlow and the finer points of Python, I've noticed these 3 statements at the top of many (perhaps most) .py files in the TensorFlow repository:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
Here are two examples:
I should clarify that I have no interest or need to support Python 2 or substantially older versions of Python 3 in any projects I'm undertaking currently.
After reading about from __future__ import xyz
statements, for example from these sources:
What is __future__ in Python used for and how/when to use it, and how it works
https://docs.python.org/2/library/future.html
https://docs.python.org/3/library/future.html
http://python-future.org/imports.html
I'm able to understand most of this documentation but I'm left with the following questions:
If only using Python 3, is there any need for these statements or can they safely be removed entirely in all cases? More specifically, if I put the following statement in the beginning of a program:
# check Python version is at least 3.6, if not, show an error and bail if sys.version_info.major < 3 or sys.version_info.minor < 6: print("ERROR: currently running Python version " + sys.version + ", at least version 3.6 is required") return # end if
Can the above statements be removed with no possibility of ill effects?
Would these statements matter in an older version of Python 3 vs a newer version of Python 3, ex. Python 3.1 vs Python 3.6?
Since TensorFlow requires Python version 3.5 or later, if these statements only matter if Python 2 (or possibly an older version of Python 3? see the previous question) is being used, why are these included in the TensorFlow codebase?
If removing these could ever cause a problem even when using a recent version of Python (ex. 3.5 or later), what would be an example to demonstrate such a problem?
-- EDIT --
user2357112 just pointed out that on Ubuntu TensorFlow supports Python 2.7 or Python 3.4:
I was honestly not aware of this as I'd been using the Windows version of TensorFlow, which requires at least Python 3.5:
So, I guess my question is specific to either a Windows TensorFlow install, or a TensorFlow install on a different OS using a recent version of 3.x.