Meta#

For models that could carry meta, they are accessible through three attributes:

txn = p.parse('''\
2000-01-01 *
    foo: 1
    ; comment
    bar: 2''', models.Transaction, auto_claim_comments=False)
txn.raw_meta_with_comments.claim_interleaving_comments()

Read:

_print_model(txn.raw_meta_with_comments[1])
_print_model(txn.raw_meta[1])
_print_model(txn.raw_meta['bar'])
print(txn.raw_meta[1].key)
print(repr(txn.meta['bar']))
print(list(txn.raw_meta.keys()))
print(list(txn.meta.values()))
    ; comment
    bar: 2
    bar: 2
bar
Decimal('2')
['foo', 'bar']
[Decimal('1'), Decimal('2')]

Write:

for i, item in enumerate(txn.raw_meta):
    item.key += '-updated'
    item.value = str(i)
_print_model(txn)

txn.raw_meta.pop(0)
txn.meta['baz'] = models.Account.from_value('Assets:Foo')
_print_model(txn)
2000-01-01 *
    foo-updated: "0"
    ; comment
    bar-updated: "1"
2000-01-01 *
    ; comment
    bar-updated: "1"
    baz: Assets:Foo