9

I'm trying to create a graphical program to deal with packages easily for end-users. However, I'm facing a problem in retrieving the package's description beside some other information.

I've seen the python-apt API here and i understood that i have to deal with the apt.package.Version() class.

But when i tried to use it, all what i got is some errors like:

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'

So, is there any body who can create a running example for the apt.package.Version() class please?

Thanks!

  • Verify that you do have long descriptions (do apt-cache show for some package). The documentation says long descriptions, so askubuntu.com/a/558389/158442 might be relevant. – muru Jan 27 '15 at 6:03
8

The following python commands should give you the long description when available:

$ 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.'
>>> 

Note: My locale are set to LANG=en_US.UTF-8 so translated strings may not be a problem here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.