问题描述
我需要执行一个根据用户平台而异的命令。我目前在Python脚本中以这种方式设置它:
import platform
user_sys = platform.system()
if user_sys == 'Linux' or 'Darwin':
cmd = "cat file1 file2..."
elif user_sys == 'Windows':
cmd = "type file1 file2..."
subprocess.run(split(cmd)) # run on command line
问题
解决方法
没有,他们不是提取此信息的更好方法,也不需要多朋友脚本。
这是我建议您可以改进的地方
from sys import platform as _platform
if _platform == "linux" or _platform == "linux2":
# linux
elif _platform == "darwin":
# MAC OS X
elif _platform == "win32":
# Windows
elif _platform == "win64":
# Windows 64-bit