Python support is now in 'next' branch

9 views
Skip to first unread message

John Wiegley

unread,
Nov 5, 2009, 2:35:12 AM11/5/09
to ledge...@googlegroups.com
Using the latest in 'next', the following now works:

import ledger
import re

account_re = "Assets:Cash"

# A poor man's register report

running_total = ledger.Value(0)

for txn in ledger.Journal("/tmp/bug.dat"):
for post in txn:
if re.match(account_re, str(post.account)):
running_total += post.amount
print "%s %-20.20s %-20.20s %12s %12s" % \
(txn.date, txn.payee, post.account, post.amount,
running_total)

Beyond just making most of the Ledger objects available so you can
drive reports from top down, like above, you can add new function's to
Ledger's value expression namespace. Any global Python function is
callable from any value expression, so long as you use --import option
to pull in the definitions. Then you can use those functions in
filters, sorting terms, automated expressions, expression-based
posting amounts, etc.

John

Reply all
Reply to author
Forward
0 new messages