python - 有没有一种Python方式可以检查OS是否是64位Ubuntu?

标签 python operating-system uname lsb

有没有一种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/

相关文章:

python - 按事件进行时间序列标准化

python - 比较两个字典列表

python - 谁更新 pip 包版本?

assembly - 您将 OS 源代码汇编或编译为什么格式?

android - 与内存备份文件相反?

linux - 如何在 Linux 中从 OS Process Sampler 执行 jar

python - 将集合转换为列表

php - php_uname() 有多快?

cmake - 如何去除CMake变量中的尾随空格?

linux-kernel - $(uname -a) 在 docker 主机或任何 docker 容器中返回相同的值