Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the last element of a PaginatedList in Python

How can I get the last element of a PaginatedList?#

(<github.PaginatedList.PaginatedList object at 0x7f1c6a492a50>).

My code is something like this - a_project_column.get_cards()[-1] and the error is

"IndexError: list index out of range"

But the below code is working fine for getting the desired result (i.e., > >ProjectCard(id=5161717))

a_project_column.get_cards()[0]

For reference https://github.com/PyGithub/PyGithub/blob/master/github/PaginatedList.py

like image 347
joydeba Avatar asked Sep 03 '25 04:09

joydeba


1 Answers

I know it's been a while, but I found the solution to this and I figured I'd provide it for anyone who should go Googling as I did, to no avail:

Instead of

a_project_column.get_cards()[-1]

Try:

cards = a_project_column.get_cards()
final_card  = cards[cards.totalCount - 1]
like image 128
tayjaybabee Avatar answered Sep 04 '25 17:09

tayjaybabee