Convert bytes to a string

后端 未结 19 2249
野性不改
野性不改 2020-11-21 04:45

I\'m using this code to get standard output from an external program:

>>> from subprocess import *
>>> command_stdout = Popen([\'ls\', \'-l         


        
19条回答
  •  野的像风
    2020-11-21 05:06

    If you should get the following by trying decode():

    AttributeError: 'str' object has no attribute 'decode'

    You can also specify the encoding type straight in a cast:

    >>> my_byte_str
    b'Hello World'
    
    >>> str(my_byte_str, 'utf-8')
    'Hello World'
    

提交回复
热议问题