Skip to content
Advertisement

Cannot unpack non-iterable int object

I need to use __getitem__ for all 7 arguments in my class but __getitem__ won’t let me so I tried to use a tuple but I keep getting this error:

JavaScript

What should I do?

JavaScript

Advertisement

Answer

To make a getitem that returns the contents of each of the member variables given a key that is the same as the name of that member, you could have the class store the information in a dict and have your get_item return from that dict. E.g.:

JavaScript

Then with an instance of the class you should be able to do things like:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement