所以我有string
个要拆分bטnew line
的内容:
此string
是process
的输出:
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'符号
答案 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'))