Convert bytes to a string

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

    def toString(string):    
        try:
            return v.decode("utf-8")
        except ValueError:
            return string
    
    b = b'97.080.500'
    s = '97.080.500'
    print(toString(b))
    print(toString(s))
    

提交回复
热议问题