Last answered:

08 Apr 2020

Posted on:

07 Apr 2020

0

Resolved: Error in TensorFlow_Audiobooks_Machine_learning_Homework

Hi,
I’ve tried to run TensorFlow_Audiobooks_Machine_learning_Homework, but I’ve gotten the following error message (I’m using Python 2 and Tensorflow 1.4.0):

TypeErrorTraceback (most recent call last)
<ipython-input-2-c3f67ecae46a> in <module>()
     72     # As a reminder, it batches samples together, one-hot encodes the targets, and returns
     73     # inputs and targets batch by batch
---> 74     for input_batch, target_batch in train_data:
     75         _, batch_loss = sess.run([optimize, mean_loss], 
     76             feed_dict={inputs: input_batch, targets: target_batch})

TypeError: instance has no next() method

The first cell of this code run without errors.
How could I solve the problem?

Thanks a lot,
Ligia Batista

1 answers ( 0 marked as helpful)
Instructor
Posted on:

08 Apr 2020

0
Hi Ligia, The error states 'instance has no next() method'. The point is that in Python 2 and Python 3, classes and methods are defined in different ways. You can read more about that here: https://portingguide.readthedocs.io/en/latest/classes.html If I remember correctly, to make it work, you needed to place double underscore before and after a method. So when you define
def next()
you should write:
def __next__()
instead. Iliya

Submit an answer