我想在python 2.7.x脚本中添加一个检查,形式为
if __check_freebsd__():
# run actions which would only work on FreeBSD (e.g. create a jail)
elif __check_debian__():
# run an alternative that runs on Debian-based systems
else:
raise Error("unsupported OS")__check_freebsd__函数会是什么样子?
我已经为__check_debian__编写了以下代码:
try:
lsb_release_id_short = sp.check_output([lsb_release, "-d", "-s"]).strip().decode("utf-8")
ret_value = "Debian" in lsb_release_id_short
return ret_value
except Exception:
return False所以你不必为此烦恼(当然,改进的建议是受欢迎的)。
发布于 2015-05-03 15:40:30
发布于 2015-05-03 15:34:03
看看os.uname。
我不是百分之百肯定,但它可能是类似于os.uname()[0] == "FreeBSD"。
发布于 2015-05-03 15:40:38
试试这个:
>>> from sys import platform
>>> platform()
# on my system I get
'linux' # check string for freebsd另外:
# below are my results
>>> import platform
>>> platform.system()
'Linux' # would be 'FreeBSD' if I was using that
>>> platform.platform()
'Linux-3.19.0-15-generic-x86_64-with-Ubuntu-15.04-vivid'https://stackoverflow.com/questions/30015665
复制相似问题