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>

<pre><code>def query(result):
    # perform query
    return result

def end_query_condition(result):
    # if want to continue query:
    return True
    # if you want to stop:
    return False

continue_query = True
result = None
while continue_query:
    result = query(result)
    continue_query = end_query_condition(result)
</code></pre>

python function loops