如何使用 Python 获取已安装的 Linux rpm 列表? [英] How to get list installed Linux rpms with Python?

查看:53
本文介绍了如何使用 Python 获取已安装的 Linux rpm 列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是subprocess.getoutput("rpm -qa").split("\n"),不是很好.rpmfile 模块只能读取 .rpm 文件

I use subprocess.getoutput("rpm -qa").split("\n"),it's not very well. rpmfile module can only read .rpm files

你能帮我找一个模块吗?

Can you help me find one module?

推荐答案

如果您使用的是 Fedora,则在 rpm-python 包中有一个名为 rpm 的模块将允许您查询 rpm 数据库:

If you are using Fedora, there is a module called rpm from the package rpm-python that will allow you to query the rpm database:

import rpm

ts = rpm.TransactionSet()
mi = ts.dbMatch()
for h in mi:
    print "%s-%s-%s" % (h['name'], h['version'], h['release'])

这是文档中的一段简单代码.请参阅此处了解更多信息.

That is a simple piece of code from the documentation. See here for more information.

这篇关于如何使用 Python 获取已安装的 Linux rpm 列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆