Py3: decode subprocess output

Tim Harig usernet at ilthio.net
Wed Nov 3 04:03:54 EDT 2010


On 2010-11-03, Gnarlodious <gnarlodious at gmail.com> wrote:
> Under Python 3, subprocess.check_output returns a bytestring that
> doesn't parse. Since the CLI program (written in the 1990's) will
> never send Unicode, is there a way to downconvert the bytestring into
> type str so as to emulate Py2.6 behavior?

str() will convert a bytestring into a Python string object which you will
be able to parse so long as the output remains ASCII (which your example
is).  If the input uses another encoding or contains characters with the
high order bit set, you might need to fiddle with the strings encoding.



More information about the Python-list mailing list