what is best method to set sys.stdout to utf-8?
Peter Kleiweg
pkleiweg at xs4all.nl
Wed Mar 7 15:57:03 EST 2012
In Python 3, there seem to be two ways to set sys.stdout to
utf-8 after the script has started:
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach())
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8')
I guess the second is better. At start-up, type(sys.stdout) is
<class '_io.TextIOWrapper'>, and it's also after using the
second method.
After using the first method, type(sys.stdout) is changed to
<class 'encodings.utf_8.StreamWriter'>.
Should I always use the second method?
--
Peter Kleiweg
http://pkleiweg.home.xs4all.nl/
More information about the Python-list
mailing list