简体   繁体   中英

Python Looping over an argument in a function

I am being a noob trying to loop over a function from pyxero:

invoices = xero.invoices.filter(page = 1)

The above call returns a list of dictionaries which becomes blank when there are no more pages left: [] . So the iteration would stop when the count of elements in the current list/page would become 0. I am trying to loop and create one big list that contains the elements from page 1 and 2 etc appended

Thanks!

Solution, (page needs to be string):

number = 1
list = []
data = xero.invoices.filter(since = datetime(2018, 1, 1), page = str(number))
while len(data) > 0 
    data = xero.invoices.filter(since = datetime(2018, 1, 1), page = str(number))
    list.append(data)
    number += 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM