Error when using beancount\parser\printer.py 'PseudoOutputFile' object has no attribute 'buffer'

33 views
Skip to first unread message

Chary Chary

unread,
Apr 6, 2019, 6:33:58 PM4/6/19
to Beancount
Hello everybody.

I was experimenting with scripting and when I run example from your document   Beancount Scripting & Plugins, I get the following error

Example:

from beancount import loader
from beancount.parser import printer


# example file, generated by beancount
filename='example.beancount'

entries, errors, options = loader.load_file(filename)

for entry in entries:
    printer.print_entry(entry)



Error

Traceback (most recent call last):
  File "C:\_code\fava&BC testing\test.py", line 14, in <module>
    printer.print_entry(entry)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\beancount\parser\printer.py", line 351, in print_entry
    output = file or codecs.getwriter("utf-8")(sys.stdout.buffer)
AttributeError: 'PseudoOutputFile' object has no attribute 'buffer'


Any idea what that might me?

I am using python 3.7 on windows 10

Martin Blais

unread,
Apr 7, 2019, 10:32:41 AM4/7/19
to Beancount
I don't know - I don't have access to Windows - but I'm probably not wrapping up stdout in an utf-8 encoder the right way.
This could be improved.


--
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+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/c47d8b86-2da8-4900-b94c-9fa27877c379%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chary Chary

unread,
Apr 7, 2019, 5:23:23 PM4/7/19
to Beancount
Martin, 

thanks.

OK, I tested the same under Unbuntu the error indeed does not come up.

To unsubscribe from this group and stop receiving emails from it, send an email to bean...@googlegroups.com.

Martin Blais

unread,
Apr 8, 2019, 1:22:32 AM4/8/19
to Beancount
There's a related discussion here:

I could potentially change this code to wrap the output encoder differently, or encode explicitly and write bytes.
Problem is, I don't have access to a Windows box, so I can't really test the differences there.
If someone's up for it, test a few of the options in the thread and let me know which works on Windows and I'll make the adjustment.


To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

Chary Chary

unread,
Apr 8, 2019, 3:34:17 AM4/8/19
to Beancount


On Monday, April 8, 2019 at 7:22:32 AM UTC+2, Martin Blais wrote:
There's a related discussion here:

I could potentially change this code to wrap the output encoder differently, or encode explicitly and write bytes.
Problem is, I don't have access to a Windows box, so I can't really test the differences there.
If someone's up for it, test a few of the options in the thread and let me know which works on Windows and I'll make the adjustment.

Martin,

if you are able to describe what needs to be done so that  an armature self-taught Python user can do it - then I am definitely willing to try

 


Chary Chary

unread,
Feb 23, 2020, 12:07:15 PM2/23/20
to Beancount
The problem on Windows is still there, but I have found workaround. The workaround is to print to file:

printer.print_entry(entry,file=open('output.txt','a'))
Reply all
Reply to author
Forward
0 new messages