我需要使用Python 3解析systemctl list-units --type=service --all --no-pager
终端输出。我需要得到输出文本的每个单元格值
为每行拆分整个输出:
text1 = subprocess.check_output("systemctl list-units --type=service --all --no-pager", shell=True).strip().decode()
text_split = text1.split("\n")
但是每一行都有空格,有些行数据也有空格。使用.split(" ")
将不起作用
我该怎么做
OS:Debian-like Linux x64 (Kernel 4.19).
下面的代码适合我。萨克森州的@Rolf和@Pietro的评论对我很有帮助。我已经使用了它们并进行了一些添加/更改
注意:对我来说没问题。可能会有错误或更合适的方法
相关问题 更多 >
编程相关推荐