有没有一种Python方式可以检查OS是否是64位Ubuntu?
目前,我一直在这样做:
import os
def check_is_linux(distro, architecture, err_msg):
try:
this_os = os.popen('lsb_release -d').read()
this_arch = os.popen('uname -a').read()
assert distro in this_os and architecture in this_arch, err_msg
except:
print(err_msg)
def check_is_64bit_ubuntu(err_msg):
check_is_linux('Ubuntu', 'x86_64', err_msg)
最佳答案
您可以使用platform
module获取分发和处理器信息:
import platform
def is_linux(distro, architecture):
if not platform.system() == 'Linux':
return False
if platform.linux_distribution()[0].lower() != distro:
return False
return platform.processor() == architecture
def is_64bit_ubuntu():
return is_linux('ubuntu', 'x86_64')
if not is_64bit_ubuntu():
print(err_msg)
关于python - 有没有一种Python方式可以检查OS是否是64位Ubuntu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31785850/