Loop a function using the previous output value as input
<p>I'm trying to query an API, but it only provides me with 100 records at a time and provides an offshoot record, which I need to use to query the next 100 records.  I can write a function to query my results, but am having trouble looping my function to use the output of the previous function as the input of the following function.  Here's what I want my loop to essentially do:</p>

<pre><code>def query(my_offset=None):
    page = at.get('Accounts',offset=my_offset)
    a = page['records']
    return str(page['offset'])

query()
query(query())
query(query(query(query())))
query(query(query(query(query()))))
query(query(query(query(query(query())))))
...
...
...
...
</code></pre>

<p>I'm guessing <code>res</code> can have a special value indicating no more rows were returned, if so, a while loop can be deployed:</p>

<pre><code>res = query()
while True:
    res = query(res)
    if not res: break
</code></pre>

<p>you just rebind the result of the query to <code>res</code> and re-use it during every iteration. </p>

python function loops