如何使用python-apt获取包描述?

Mad*_*dno 9 package-management python apt

我正在尝试创建一个图形程序来为最终用户轻松处理包。但是,除了一些其他信息之外,我在检索包的描述时遇到了问题。

我在这里看到了 python-apt API,我知道我必须处理apt.package.Version() class

但是当我尝试使用它时,我得到的只是一些错误,例如:

Traceback (most recent call last):
File "./myprogram", line 6, in <module>
print package.description
File "/usr/lib/python2.7/dist-packages/apt/package.py", line 374, in description
dsc = self._translated_records.long_desc
File "/usr/lib/python2.7/dist-packages/apt/package.py", line 315, in _translated_records
desc_iter = self._cand.translated_description
AttributeError: 'list' object has no attribute 'translated_description'
Run Code Online (Sandbox Code Playgroud)

那么,有没有人可以为 apt.package.Version() 类创建一个运行示例?

谢谢!

Syl*_*eau 8

以下 python 命令应在可用时为您提供详细描述:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt
>>> cache = apt.Cache()
>>> pkg = cache['python2.7']
>>> pkg
<Package: name:'python2.7' architecture='amd64' id:1247L>
>>> pkg.versions
<VersionList: ['2.7.6-8']>
>>> pkg.versions[0]
<Version: package:'python2.7' version:'2.7.6-8'>
>>> pkg.versions[0].description
u'Python is a high-level, interactive, object-oriented language. Its 2.7 version
includes an extensive class library with lots of goodies for network programming, 
system administration, sounds and graphics.'
>>> 
Run Code Online (Sandbox Code Playgroud)

注意:我的语言环境设置为LANG=en_US.UTF-8这样翻译的字符串在这里可能不是问题。