[Tutor] getting __doc__ strings

Kalle Svensson kalle@lysator.liu.se
Fri Nov 29 16:16:48 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Eric Black]
> Hi Listers,
>    I'm a newbie at this, but here's a scrap 
> of code I'm kind of proud of. It's a fast, 
> handy way to get quick, concise documentation 
> on a lot of cogs in Python.  
...

Very nice!  Accessing documentation strings and other information
about objects dynamically is a useful feature of Python.

> def doc(a):
>     for eachAttribute in dir(a):
>         print '***' + eachAttribute + '***'

>         e = 'a.' + eachAttribute + '.__doc__'
>         print eval( e )

These two lines can also be written as

         print getattr(a, eachAttribute).__doc__

to avoid using eval().

>         print

If you're using Python 2.2, you might also want to look at the
built-in function help().

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE959jKdNeA1787sd0RAsJhAKCeOM3BGT/+Ok4iYBVbRHiN8aYT5ACeMSzd
0+3S4Nk+vqShj46eA/n01dA=
=v3sx
-----END PGP SIGNATURE-----