[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:13:26 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:
(You can also check for an empty list after the loop, e.g. this will print "No results" only when the list is empty):
```python
mi = ts.dbMatch("name", name)
for hdr in mi:
...
if not mi:
print("No results")
```
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3177#discussion_r1696065634
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/3177/review/2206264607 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240729/ec4ef1b8/attachment-0001.html>
More information about the Rpm-maint
mailing list