[Rpm-maint] [rpm-software-management/rpm] Add real-life examples of Python RPM (PR #3177)

Frank Dana notifications at github.com
Mon Jul 29 23:08:52 UTC 2024


@ferdnyc commented on this pull request.



> @@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+# Query a single installed package by its name.
+# A Python equivalent for `rpm -q hello`
+
+import rpm
+
+name = "hello"
+ts = rpm.TransactionSet()
+mi = ts.dbMatch("name", name)
+hdr = next(mi, None)
+if hdr:

Looping over the return value (`for hdr in mi:`) also has the advantage that you can skip the `next()` call and the `if hdr` check; if an empty list is returned it will simply cause the loop the be skipped.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3177#discussion_r1696063040
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/pull/3177/review/2206253992 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240729/93f6ff05/attachment.html>


More information about the Rpm-maint mailing list