Why tf.Variable is iterable but can't be iterated
<p>Why this is true:</p>

<pre><code>from collections import Iterable
import tensorflow as tf

v = tf.Variable(1.0)
print(isinstance(v, Iterable))

True
</code></pre>

<p>while this</p>

<pre><code>iter(v)
</code></pre>

<p>gives</p>

<pre><code>TypeError: 'Variable' object is not iterable.
</code></pre>

<p>I found below method in Tensorflow's Variable class: </p>

<pre><code>def __iter__(self):
    """Dummy method to prevent iteration. Do not call.
    NOTE(mrry): If we register __getitem__ as an overloaded operator,
    Python will valiantly attempt to iterate over the variable's Tensor from 0
    to infinity.  Declaring this method prevents this unintended behavior.
    Raises:
      TypeError: when invoked.
    """
    raise TypeError("'Variable' object is not iterable.")
</code></pre>

<p><a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/variables.py#L366" rel="nofollow">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/variables.py#L366</a></p>

python python-2.7 tensorflow iterable