[BangPypers] recursion not working

Kenneth Gonsalves lawgon at au-kbc.org
Mon Mar 15 09:24:38 CET 2010


hi,

here is a function I have written:

def getaccbal(accnt,bal):
    account = Account.objects.get(pk=accnt)
    
    if account.vouch:
        bal = bal + getledgerob(account)
    else:
        children = account.account_set.all()
        for child in children:
            getaccbal(child.id,bal)
    return bal

if I try this with bal=0, on each recursion bal gets reset to 0 and I always 
get a 0 as a result. (If I put bal=20, result is 20). Must be something very 
simple that I am missing.
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in


More information about the BangPypers mailing list