[BangPypers] recursion not working

Shekhar pythonic at gmail.com
Mon Mar 15 09:46:37 CET 2010


Kenneth Gonsalves wrote:
> 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
>   
may be

    for child in children:
        bal += 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.
>   



More information about the BangPypers mailing list