2017-10-16 23:01:36 Martin Blais <bl...@furius.ca>:
> 
> In order to do that, I would suggest going LO-FI and using sed (or Python), 
> and working off of the input text directly.
> Working off of the parsed input will just cause you headaches.
> 

I had a few similar use cases with Holger -- renaming a account while
preserving the indentation and whitespace, reformat the payee +
narration field, etc.

I found the fileinput module from Python stdlib extremely useful in
these cases:


with fileinput.input('ledger.bean', inplace=True) as f:
    for line in f:
        new_line = process_line(line)
        print(new_line, end='')


With inplace=True parameter, it's like `sed -i`, but with all the
powerful batteries of Python.


-- 
Zhuoyun Wei

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beancount+unsubscr...@googlegroups.com.
To post to this group, send email to beancount@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/20171017075841.GA4020%40herus.wzyboy.org.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: PGP signature

Reply via email to