python> from six.moves import xrange> Six: Python 2 and 3 compatibility library> python2: xrange () / python3: range ()

I'm learning python code for Deep Learning related things called TensorFlow. https://www.tensorflow.org/versions/master/tutorials/mnist/tf/index.html#tensorflow-mechanics-101

About the following description in that fully_connected_feed.py

from six.moves import xrange  # pylint: disable=redefined-builtin

http://hhsprings.bitbucket.org/docs/translations/python/six-doc-ja/

Six provides a simple utility to absorb the differences between Python 2 and Python 3.

There is a correspondence table at the bottom of the same page.

Six names Python 2 people Python 3 people
... ... ...
range xrange() range
... ... ...

Six names will make it easier to support Python3.

However, in fully_connected_feed.py, it is described by Python2 name as follows, so it must be rewritten after all when supporting Python3.

    # Start the training loop.
    for step in xrange(FLAGS.max_steps):

You can also try the following, and Precision is the same.

    # Start the training loop.
    for step in range(FLAGS.max_steps):

In the original fully_connected_feed.py, commenting out the following does not cause any problems, so I feel that Six is not used after all.

from six.moves import xrange  # pylint: disable=redefined-builtin

Recommended Posts

python> from six.moves import xrange> Six: Python 2 and 3 compatibility library> python2: xrange () / python3: range ()
About Python, from and import, as
range and xrange
python> link> range () / xrange ()
Python from or import
[Python of Hikari-] Chapter 08-03 Module (Import and use of standard library)
python> link> from __future__ import absolute_import
Read and use Python files from Python
Python3> List generation from iterable> list (range (5))
From Python to using MeCab (and CaboCha)
Porting and modifying doublet-solver from python2 to python3.
Module import and exception handling in python