Seite 1 von 1

Informationen über ein Modul

Verfasst: Sonntag 21. Februar 2010, 11:28
von snafu
Für alle, die wichtige Informationen auf einem Blick haben wollen, ohne gleich etwas wie IPython installieren zu müssen, hier ein paar Zeilen:

Code: Alles auswählen

META_ATTRS = (
    '__name__','__author__','__version__','__license__','__file__','__all__'
)

def metainfo(module, attrs=None):
    return dict(
        (attr, getattr(module, attr)) 
        for attr in attrs or META_ATTRS
        if hasattr(module, attr)
    )

def infostring(module):
    return '\n'.join(
        '%s: %s' % (k.strip('__').capitalize(), v) 
        for (k,v) in metainfo(module).iteritems()
    )

Code: Alles auswählen

>>> print metainfo.infostring(BeautifulSoup)
Name: BeautifulSoup
File: /usr/local/lib/python2.6/dist-packages/BeautifulSoup.pyc
Version: 3.0.7a
License: New-style BSD
Author: Leonard Richardson (leonardr@segfault.org)

Verfasst: Montag 22. Februar 2010, 00:36
von snafu