How to convert my bytearray('b\x9e\x18K\x9a') to something like this--> '\x9e\x18K\x9a'<---just str ,not array

前端 未结 1 1802

How to convert my bytearray(\'b\\x9e\\x18K\\x9a\') to something like this --> \\x9e\\x18K\\x9a <---just str, not array!



        
1条回答
  •  悲&欢浪女
    2021-01-13 07:54

    In 2.x, strings are bytestrings.

    >>> str(bytearray('b\x9e\x18K\x9a'))
    'b\x9e\x18K\x9a'
    

    Latin-1 maps the first 256 characters to their bytevalue equivalents, so in Python 3.x:

    3>> bytearray(b'b\x9e\x18K\x9a').decode('latin-1')
    'b\x9e\x18K\x9a'
    

    0 讨论(0)
提交回复
热议问题