[Rpm-maint] [rpm-software-management/rpm] Add real-life examples of Python RPM (PR #3177)
Panu Matilainen
notifications at github.com
Mon Jun 24 09:49:44 UTC 2024
@pmatilai commented on this pull request.
> @@ -0,0 +1,11 @@
+#!/usr/bin/python3
+
+# Query all installed packages.
+# A Python equivalent for `rpm -qa`
+
+import rpm
+
+ts = rpm.TransactionSet()
+mi = ts.dbMatch()
+for hdr in mi:
This isn't wrong in such a small example of course, but assigning the match iterator to a variable can leave the database cursor open for much longer than intended. With read-cursors it's not a big deal with in the post BerkeleyDB world, but when you don't actually need the match iterator handle outside the loop (ie the usual case), I'd recommend this style instead:
```
for hdr in ts.dbMatch(...):
# do stuff
```
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3177#pullrequestreview-2135262698
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/3177/review/2135262698 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240624/71d750f7/attachment.html>
More information about the Rpm-maint
mailing list