Print docstrings to shell

André Roberge andre.roberge at gmail.com
Wed Feb 2 01:30:47 CET 2011


On Tuesday, February 1, 2011 8:11:51 PM UTC-4, Gnarlodious wrote:
> Can I run a script in bash and print out its docstrings to the bash
> shell? I tried this at the end:
> 
> print(help(__file__))
> 
> Runnig the script:
> python ~/Sites/Sectrum/Harmonics.py
> 
> but all it spit out was:
> 
> no Python documentation found for '~/Sites/Sectrum/Harmonics.py'
> 
> 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.
> 
> -- Gnarlie

Try the following:

============test.py======
import pydoc

'''this is a test'''

class A(object):
	'''docstring'''
	pass

print(pydoc.help(__file__[:-3]))
=============

python test.py

André



More information about the Python-list mailing list