naive doc question

Michael Tobis mt at 3planes.com
Sun Jan 30 02:46:29 CET 2005


I wouldn't call the responses here helpful; they seem overspecific. I
had a similar problem which led to the follwing code. After I came up
with this I saw a very similar utility was derived in Dive into Python.


see
http://diveintopython.org/power_of_introspection/index.html#apihelper.divein

Anyway the following is intended as an interactive utility to explore
the callables of modules and classes. I always have it imported into my
interactive sessions.

So import it and try

sm(dict)

.########################################################
.# sm()
.# showmethods
.
.def sm(namespace,terse=0,maxchars=300):
.
.   """report the callables of a namespace
.
.returns a nice string representation of the public callables of the
.namespace and the first maxchars bytes of their respective docstrings
.
.if terse, truncates the docstring at the first newline
.   """
.
.   d = namespace.__dict__
.   l = [str(x) + "\t\t" + str(d[x].__doc__)[:maxchars] for x in
d.keys() \
.            if callable(d[x]) and not x.startswith("_")]
.   if terse:
.      l = [x.split("\n")[0] for x in l]
.   l.sort()
.   return "\n=====\n".join(l)




More information about the Python-list mailing list