🛠️ Scheduled Maintenance | We’ll be undergoing scheduled maintenance and upgrades between 00:00 PST Jan 26th until 00:00 PST Jan 28th. There may be brief interruption of services in that period. We apologize for the inconvenience.

The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

Error in TensorFlow_Audiobooks_Machine_learning_Homework

Error in TensorFlow_Audiobooks_Machine_learning_Homework


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

edit delete flag

1 Answer

365 Team

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__()