import piecash # open the book named test_book.gnucash with piecash.open_book("test_book.gnucash") as b: # iterate on all the accounts and print the fullname # the order is the order in the database # # Assets # Assets:Investments # Assets:Investments:Brokerage Account # Assets:Investments:Brokerage Account:Bond # Assets:Investments:Brokerage Account:Stock for acc in b.accounts: print(acc.fullname) # walk down the account structure and run function f on each account def walk(acc, f): f(acc) for subacc in acc.children: walk(subacc, f) # function that prints the fullname account replacing the ":" by "," def print_fullname(acc): print(acc.fullname.replace(":",",")) # walk ! # # Assets # Assets,Investments # Assets,Investments,Brokerage Account # Assets,Investments,Brokerage Account,Bond # Assets,Investments,Brokerage Account,Stock walk(b.root_account, print_fullname)