Convert bytes to a string

后端 未结 19 2326
野性不改
野性不改 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:09

    If you want to convert any bytes, not just string converted to bytes:

    with open("bytesfile", "rb") as infile:
        str = base64.b85encode(imageFile.read())
    
    with open("bytesfile", "rb") as infile:
        str2 = json.dumps(list(infile.read()))
    

    This is not very efficient, however. It will turn a 2 MB picture into 9 MB.

提交回复
热议问题