Accessing the Journal when Embedding Python

58 views
Skip to first unread message

ELI

unread,
Nov 2, 2014, 1:55:42 PM11/2/14
to ledge...@googlegroups.com
When embedding python in a ledger file, how do I access the current journal from the session?

- Harpreet "Eli" Sangha

John Wiegley

unread,
Nov 2, 2014, 3:22:00 PM11/2/14
to ledge...@googlegroups.com
>>>>> ELI <eli...@gmail.com> writes:

> When embedding python in a ledger file, how do I access the current journal
> from the session?

I don't believe the whole journal is ever surfaced as on object the Python
API. If it were, it would be an object called "journal"..

John

ELI

unread,
Nov 2, 2014, 3:54:56 PM11/2/14
to ledge...@googlegroups.com

Would this be a viable feature request?

- Harpreet "Eli" Sangha

--

---
You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Blais

unread,
Nov 2, 2014, 4:08:08 PM11/2/14
to ledger-cli
Just curious, what's your use case? 
Backing up one step, what are you trying to achieve?

ELI

unread,
Nov 2, 2014, 4:19:19 PM11/2/14
to ledge...@googlegroups.com

I'm trying to implement a custom balance assertion in my ledger file. So, I want to access the balance of a specified account.

- Harpreet "Eli" Sangha

Martin Blais

unread,
Nov 2, 2014, 5:00:06 PM11/2/14
to ledger-cli
If it's not too indiscreet, what's the use case behind the assertion?
What high-level problem are you trying to solve?


ELI

unread,
Nov 2, 2014, 5:19:15 PM11/2/14
to ledge...@googlegroups.com

When reconciling stock holdings with brokerage statements I want to be able to just punch in the holdings as displayed on the statement and:
1) Assert that any commodities that are not specified have a zero balance.
2) Compare commodities that are specified with the precision (rounding) used on the statement.

- Harpreet "Eli" Sangha

John Wiegley

unread,
Nov 3, 2014, 11:46:31 AM11/3/14
to ledge...@googlegroups.com
>>>>> ELI <eli...@gmail.com> writes:

> Would this be a viable feature request?

Sure! And looking at the source code, the journal object *is* made available
to the Python API.

John

ELI

unread,
Nov 3, 2014, 8:04:34 PM11/3/14
to ledge...@googlegroups.com

John,

I see journal methods exposed, but not the journal object itself.  Can you provide the attribute (i.e. ledger.journal, ledger.session.journal) or the source you've referring to?

- Harpreet "Eli" Sangha

ELI

unread,
Nov 4, 2014, 11:47:39 PM11/4/14
to ledge...@googlegroups.com
So, accessing the journal object aside, I'm having trouble retrieving the balance of an account from python.  I also noticed that the journal and account accesses are commending out in python/demo.py in the ledger source.  Any thoughts?

>>> account.amount()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    Account.amount(Account)
did not match C++ signature:
    amount(ledger::account_t {lvalue}, boost::optional<ledger::expr_t&>)
>>> account.total()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    Account.total(Account)
did not match C++ signature:
    total(ledger::account_t {lvalue}, boost::optional<ledger::expr_t&>)



- Harpreet "Eli" Sangha

John Wiegley

unread,
Nov 12, 2014, 2:04:40 PM11/12/14
to ledge...@googlegroups.com
>>>>> ELI <eli...@gmail.com> writes:

> So, accessing the journal object aside, I'm having trouble retrieving the
> balance of an account from python. I also noticed that the journal and
> account accesses are commending out in python/demo.py in the ledger
> source. Any thoughts?

>>>> account.amount()

I don't think these attributes are functions.

John

ELI

unread,
Nov 12, 2014, 4:58:51 PM11/12/14
to ledge...@googlegroups.com
They are, at least on the version I've checked out.  I've made changes locally to fix the issues I've run into thus far and will submit a pull request when I'm in a good state to do so.

- Harpreet "Eli" Sangha


John

John Wiegley

unread,
Nov 12, 2014, 5:24:48 PM11/12/14
to ledge...@googlegroups.com
>>>>> ELI <eli...@gmail.com> writes:

> They are, at least on the version I've checked out. I've made changes
> locally to fix the issues I've run into thus far and will submit a pull
> request when I'm in a good state to do so.

Ah, ok, thanks!

John
Reply all
Reply to author
Forward
0 new messages