Bug#571443: Support using "in" operator to test whether a package is in the cache
Am Donnerstag, den 25.02.2010, 06:53 -0800 schrieb Matt Kraai:
> Package: python-apt
> Version: 0.7.93.1
> Severity: wishlist
>
> Hi,
>
> I'm using python-apt's apt_pkg.Cache class to determine which packages
> are installed. I have to use a try...except statement to check
> whether a package is in the cache first, though, since using the "in"
> operator to do so generates an exception:
>
> Python 2.5.5 (r255:77872, Feb 1 2010, 19:53:42)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import apt_pkg
> >>> apt_pkg.init()
> >>> cache = apt_pkg.Cache()
> Reading package lists... Done
> Building dependency tree
> Reading state information... Done
> >>> 'foo' in cache
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: argument of type 'apt_pkg.Cache' is not iterable
> >>>
>
> I wish that this worked.
Use::
'foo' in cache.packages
I could also try to implement most of the mapping stuff in
apt_pkg.Cache, so one can just treat the cache as a mapping.
--
Julian Andres Klode - Debian Developer, Ubuntu Member
See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.
Reply to: