gpt4 book ai didi

python - 有没有一种Pythonic方法来检查操作系统是否是64位Ubuntu?

转载 作者:行者123 更新时间:2023-11-30 23:08:16 25 4
gpt4 key购买 nike

有没有一种Pythonic方法来检查操作系统是否是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 - 有没有一种Pythonic方法来检查操作系统是否是64位Ubuntu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31785850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com