Typeerror: 'githubiterator' Object Does Not Support Indexing
Solution 1:
I'm pretty sure the first line of your code doesn't do what you want. You're trying to index (with [-1]
) an object that doesn't support indexing (it is some kind of iterator). You've also go a list call wrapped around it, and a loop running on that list. I think you don't need the loop. Try:
comments = list(GitAuth.repo.issue(prs.number).comments())[-1]
I've moved the closing parenthesis from the list
call to come before the indexing. This means the indexing happens on the list, rather than on the iterator. It does however waste a bit of memory, since all the comments get stored in a list before we index the last one and throw the list away. If memory usage is a concern, you could bring back the loop and get rid of the list
call:
for comments in GitAuth.repo.issue(prs.number).comments():
pass # the purpose of this loop is to get the last `comments` value
The rest of the code should not be inside this loop. The loop variable comments
(which should probably be comment
, since it refers to a single item) will remain bound to the last value from the iterator after the loop ends. That's what you want to do your search on.
Post a Comment for "Typeerror: 'githubiterator' Object Does Not Support Indexing"