The Python Oracle

Python: TypeError: argument of type 'Comment' is not iterable

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay

--

Chapters
00:00 Question
01:41 Accepted answer (Score 7)
02:22 Thank you

--

Full question
https://stackoverflow.com/questions/2427...

Accepted answer links:
[From the ]: http://praw.readthedocs.org/en/latest/pa...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #runtimeerror #bots #reddit

#avk47



ACCEPTED ANSWER

Score 7


has_feels = 'feels' in comment

comment here looks to be an object with attributes which inherently is not iterable like a list or a string.

From the praw documentation, you need to access the comment's text via the body attribute:

So something like:

has_feels = 'feels' in comment.body

Here's some examples about why what you're current doing does not work:

>>> "x" in "xxyy"  # works (string is iterable)
>>> "x" in ["x", "y"]  # works (list is iterable)

>>> class MyClass(): pass
>>> c = MyClass()
>>> "y" in c
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument of type 'instance' is not iterable