But why are you trying to do this? What's your purpose?

> A workaround I see, is to read in main.beancount and write out the
entries to different files based on entries[6].meta["filename"]. Basically
rewriting the entire ledger.

I was going to suggest this.
Still, when you write entries out, they won't look precisely the same as
the input. Numbers will have been filled in, cost bases will show up, etc.
I don't see the point.



On Mon, May 13, 2019 at 10:36 AM Florian Lindner <mailingli...@xgm.de>
wrote:

> I see.
>> Well FWIW, entries which have errors are not guaranteed to show up in the
>> output stream at all.
>> It's unclear to me whether this is always the best outcome, but a long
>> while ago I decided to do this for transactions and for some other
>> directives.
>>
>> https://bitbucket.org/blais/beancount/src/d1b2cbf2841669e988f6692ec1d39db3708730cc/beancount/ops/balance.py#lines-119
>>
>> I don't have a solution for you. This is an unusual case.
>>
>
> I tried to apply the workaround I mentioned:
>
>     entries, error, option_map = bc.loader.load_file(args.inputfile)
>     sorted_entries = {} # file -> list of entries
>
>     for e in entries:
>         entry = transform_txn(e) if type(e) == data.Transaction else e
>         name = entry.meta["filename"]
>         sorted_entries[name] = sorted_entries.get(name, []) + [entry]
>
>     for filename in sorted_entries:
>         with open(filename, "w") as f:
>             bc.parser.printer.print_entries(sorted_entries[filename], file
> = f)
>
> A problem that shows up, is that in main.beancount I have some options set
> (e.g. operation_currency). They don't show up in entries, but in
> option_map. However, I don't know how to write them to file.
>
> Another idea: At a first try, it seems that reading the entire file into a
> string and use beancount.parser.parser.parse_many would work and also
> parser the balances:
>
>     with open(args.inputfile, "r") as f:
>         instr = f.read()
>
>     entries = bc.parser.parser.parse_many(instr)
>
> Seems to work fine so far. What do you think?
>
> Best,
> Florian
>
> --
> 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/04ece178-cb20-4f9f-9fe0-33076c88c1c7%40googlegroups.com
> <https://groups.google.com/d/msgid/beancount/04ece178-cb20-4f9f-9fe0-33076c88c1c7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAK21%2BhNqzzSYG0KZkbmZMc0v8FJfpcMpN%3DA9YR2d906hE7fK%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to