我想在 python 中打印 Pi 的操作系统系统信息。操作系统命令“cat /etc/os-release”在具有良好行格式的终端中运行良好。
在 Python 中,我使用了:
import subprocess
output = subprocess.check_output("cat /etc/os-release", shell=True)
print("Version info: ",output)
Run Code Online (Sandbox Code Playgroud)
这有效,但我没有得到任何换行符:
Version info: b'PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"\nNAME="Raspbian GNU/Linux"\nVERSION_ID="9"\nVERSION="9 (stretch)"\nID=raspbian\nID_LIKE=debian\nHOME_URL="http://www.raspbian.org/"\nSUPPORT_URL="http://www.raspbian.org/RaspbianForums"\nBUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"\n'
Run Code Online (Sandbox Code Playgroud)
如何格式化输出以添加换行符?