외부 프로그램의 표준 출력을 bytes
개체로 캡처했습니다.
>>> from subprocess import *
>>> command_stdout = Popen(['ls', '-l'], stdout=PIPE).communicate()[0]
>>>
>>> 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'
다음과 같이 인쇄할 수 있도록 일반 Python 문자열로 변환하고 싶습니다.
>>> 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
방법을 시도했지만 binascii.b2a_qp()
동일한 bytes
개체를 다시 얻었습니다.
>>> 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'
bytes
개체를 str
Python 3 으로 어떻게 변환 합니까?