Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beeprint interacts badly with wrapped sys.stdout #21

Open
jhermann opened this issue Mar 30, 2017 · 2 comments
Open

beeprint interacts badly with wrapped sys.stdout #21

jhermann opened this issue Mar 30, 2017 · 2 comments

Comments

@jhermann
Copy link

Concrete example is bpython, this is what happens:

$ bpython
bpython version 0.16 on top of Python 2.7.11+
>>> import sys
>>> sys.stdout
<bpython.curtsiesfrontend.coderunner.FakeOutput object at 0x7f6a156c0b50>
>>> import beeprint
>>> sys.stdout<open file '<stdout>', mode 'w' at 0x7f6a1a2a6150>

I don't know why sys.stdout is changed at all by a simple import (it shouldn't), but if you do, chain the existing value.

@jhermann
Copy link
Author

And I found the culprit:

if pyv == 2:
# avoid throw [UnicodeEncodeError: 'ascii' codec can't encode characters]
# exceptions, without these lines, the sys.getdefaultencoding() returns ascii
from imp import reload
reload(sys)
sys.setdefaultencoding('utf-8')

What you do there is just horrible.

@gimbo
Copy link

gimbo commented Apr 12, 2019

I've just come across this issue too (with jupyter not bpython, but I guess it's the same thing); python 2.7.13 and beeprint 2.4.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants