printing a list of doc strings
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Fri Apr 21 11:11:47 EDT 2000
schmitthead at my-deja.com wrote in comp.lang.python:
> What I had in mind was something like this:
>
> for i in dir(os):
> print eval( string.join( str(
> i ), "__doc__" ) )
>
> Any advice? I just want a list of all the items
> in os with their doc
> strings.
Well, it's something like that alright. How about:
for i in dir(os):
print eval("os.%s.__doc__" % i)
Of course, this gives an exception for object that have no __doc__, like int
constants.
Probably the best thing is to use __dict__:
for (name, object) in os.__dict__.items():
if hasattr(object, '__doc__'):
print "Docstring of object os.%s:" % name
print object.__doc__
else:
print "Object os.%s has no docstring." % name
--
Remco Gerlich, scarblac at pino.selwerd.nl
-rwxr-xr-x 1 root 5.89824e37 Oct 22 1990 /usr/bin/emacs [STR]
More information about the Python-list
mailing list