[New-bugs-announce] [issue44774] incorrect sys.stdout.encoding within a io.StringIO buffer

Pierre Carbonnelle report at bugs.python.org
Fri Jul 30 04:52:55 EDT 2021


New submission from Pierre Carbonnelle <pierre.carbonnelle at gmail.com>:

The following code 

    print("outside:", sys.stdout.encoding)
    with redirect_stdout(io.StringIO()) as f:
        print("inside: ", sys.stdout.encoding)
    print(f.getvalue())

yields:

    outside: utf-8
    inside:  None

Because StringIO is a string buffer, the expected result is:

    outside: utf-8
    inside:  utf-8

This creates problem when using packages whose output depends on the sys.stdout.encoding, such as z3-solver.

----------
components: Library (Lib)
messages: 398528
nosy: pcarbonn
priority: normal
severity: normal
status: open
title: incorrect sys.stdout.encoding within a io.StringIO buffer
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44774>
_______________________________________


More information about the New-bugs-announce mailing list