我正在尝试创建一个图形程序,以便最终用户轻松处理软件包。但是,我在检索软件包描述以及其他一些信息时遇到了问题。
我已经在这里看到了 python-apt API,我明白我必须处理apt.package.Version()
班级。
但是当我尝试使用它时,我得到的只是一些错误,例如:
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'
那么,有谁可以为 apt.package.Version() 类创建一个运行示例吗?
谢谢!
答案1
以下 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.'
>>>
笔记:我的语言环境设置为LANG=en_US.UTF-8
,因此翻译的字符串在这里可能不是问题。