Python: TypeError: argument of type 'Comment' is not iterable
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay
--
Chapters
00:00 Python: Typeerror: Argument Of Type 'Comment' Is Not Iterable
01:18 Accepted Answer Score 7
01:47 Thank you
--
Full question
https://stackoverflow.com/questions/2427...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #runtimeerror #bots #reddit
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay
--
Chapters
00:00 Python: Typeerror: Argument Of Type 'Comment' Is Not Iterable
01:18 Accepted Answer Score 7
01:47 Thank you
--
Full question
https://stackoverflow.com/questions/2427...
--
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