Print docstrings to shell

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Feb 2 04:57:30 EST 2011


On Tue, 01 Feb 2011 16:11:51 -0800, Gnarlodious wrote:

> Can I run a script in bash and print out its docstrings to the bash
> shell? I tried this at the end:
[...]
> However in the interactive shell it prints out the class structure
> nicely. What I really want to see is this output in the bash window.

Use the Source, Luke :)

See what help() does, and modify it appropriately. See the site and pydoc 
modules for more information.

But there's no need to reinvent the wheel. pydoc already does what you 
want (or at least what I think you want). Just run "pydoc name" from 
bash. So long as name is a module in the python path (in other words, so 
long as "import name" will work), then pydoc will see it too. If you want 
to write the output out to a file, use "pydoc -w name".


-- 
Steven



More information about the Python-list mailing list