Roberto Sánchez added the comment:

In my case, I modify the stdout but the error was thrown by a third party 
(click lib), I need to overwrite the stdout because the program has a CLI and 
the locale env in the terminal seems to be wrong:
 codecs.lookup(locale.getpreferredencoding()).name == 'ascii'
 sys.getdefaultencoding() == 'utf-8'

For these cases I try to fix it forcing the the IO encoding to the value given 
by sys.getdefaultencoding(), otherwise the script in a CLI won't work properly. 

I can apply a monkey-patch on the third party method that return 
"os.get_terminal_size()" if a ValueError exception is thrown, actually, The 
script is working now with the monkey-patch, but I thought that a bit of more 
"magic" in get_terminal_size would help to deal with the encoding issues in 
python3 CLI programs.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24966>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to