Can I list the functions inside a module
scott
smarsh at hotmail.com
Sun Jul 1 01:53:36 EDT 2001
Calvin Fong wrote:
>
> Greetings,
> I'm running Piggy 0.7 on my palm m100. Piggy is a python interperter for
> palm OS. As there is some platform specific modules for it, I want to
> know what function do they contain. Please, can anyone teach me how to
> show the function inside a modules.
>
The following code is from the tutorial "Dive into Python"
(http://diveintopython.org/apihelper_divein.html#apihelper.divein) :
# apihelper.py
def help(object, spacing=10, collapse=1):
"""Print methods and doc strings.
Takes module, class, list, dictionary, or string."""
methodList = [e for e in dir(object) if callable(getattr(object,
e))]
processFunc = collapse and (lambda s: " ".join(s.split())) or
(lambda s: s)
print "\n".join(["%s %s" %
(method.ljust(spacing),
processFunc(str(getattr(object, method).__doc__)))
for method in methodList])
if __name__ == "__main__":
print help.__doc__
More information about the Python-list
mailing list