用换行符分隔后的第一个位置的'b'字符

时间:2019-05-14 14:55:43

标签: python

所以我有string个要拆分bטnew line的内容: 此stringprocess的输出:

tshark_path=r'C:\Program Files\Wireshark\tshark.exe'
process = Popen([tshark_path, "-D"], stdout=PIPE, shell=True)
(output, err) = process.communicate()
exit_code = process.wait()

lines = [s.strip() for s in output.splitlines()]
for line in lines:
    print(line)

每个打印行始终以'b'开头,尽管在我的output变量(process输出中)只出现一次'b'符号

1 个答案:

答案 0 :(得分:0)

b表示字节字面量。请使用decode来获取字符串。

from subprocess import Popen, PIPE

tshark_path=r'dir/w'
process = Popen([tshark_path, "-D"], stdout=PIPE, shell=True)
(output, err) = process.communicate()
exit_code = process.wait()

lines = [s.strip() for s in output.splitlines()]
for line in lines:
    print(line.decode('utf-8'))