''builtin_function_or_method' object is not iterable
I'm trying to print all cars in stuff from this json:
{
"stuff": [
{
"car" : 1,
"color" : "blue"
},
{
"bcarus" : 2,
"color" : "red"
}
],
}
In my Serializer I access the data like this....
stuff = self.context.get("request").data.stuff
But when I do the following...
for item in stuff:
print(item)
I get he error:
'builtin_function_or_method' object is not iterable
Why do I get this error?
How can I access stuff in a for loop?
When I do print(self.context.get("request").data.stuff) I get <built-in method items of dict object at 0x105225050> which I assumed print the stuff instead.
Solution 1:[1]
my_dict={"Car1":"Audi","Car2":"BMW","Car3":"Audi"}
for x in my_dict.values:
print(x)
'builtin_function_or_method' object is not iterable
This may be because my_dict.values is a function that is expecting empty "()" or some value in it
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Henry Ecker |
