This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients Camion, eric.smith
Date 2017-12-09.12:40:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512823253.03.0.213398074469.issue32259@psf.upfronthosting.co.za>
In-reply-to
Content
The error message is correct, but I'm sorry it's confusing.

Here's an equivalent error:

a, b = 3

You'll get the error "TypeError: 'int' object is not iterable". That's because Python sees 2 items to the left of the assignment, so it needs to extract 2 items from the right side. To get 2 values from the right side, it iterates over the right side. In this case, 3 cannot be iterated over, thus the error message.

Now consider:

a, b = 3, 4

Again, to get 2 items from the right side, Python iterates over it. In this case the thing on the right side is a 2 element tuple. It's a little confusing that it's a tuple because it doesn't have parentheses, but the comma between 3 and 4 makes it a tuple. In this case, Python can iterate over the tuple, and the tuple has exactly 2 elements, so the assignment to a and b succeeds with a = 3 and b = 4.

I hope that clears it up.
History
Date User Action Args
2017-12-09 12:40:53eric.smithsetrecipients: + eric.smith, Camion
2017-12-09 12:40:53eric.smithsetmessageid: <1512823253.03.0.213398074469.issue32259@psf.upfronthosting.co.za>
2017-12-09 12:40:52eric.smithlinkissue32259 messages
2017-12-09 12:40:52eric.smithcreate