>>> command_stdoutb'total 0\n-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file1\n-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file2\n' - N0 q, d8 [6 Z
但是,我想用输出作为普通 Python 字符串。这样我就可以这样打印了: u! q, Q% I* X
>>> print(command_stdout)-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file1-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file2 ]* ?; _0 `! }
我想这就是binascii.b2a_qp()使用方法,但当我尝试它时,我得到了相同的字节数组: 0 t- Z7 ]# j2 r$ W) M/ t. _9 X
>>> binascii.b2a_qp(command_stdout)b'total 0\n-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file1\n-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file2\n' ( Y* A( z, p' ~! J8 ^
>>> b"abcde"b'abcde'# utf-8 is used here because it is a very common encoding,but you# need to use the encoding your data is actually in.>>> b"abcde".decode("utf-8") 'abcde'0 W. V) ] k+ s5 ]: l