Print docstrings to shell
André Roberge
andre.roberge at gmail.com
Tue Feb 1 20:21:48 EST 2011
On Tuesday, February 1, 2011 9:05:28 PM UTC-4, Gnarlodious wrote:
> On Feb 1, 5:30 pm, André Roberge <andre.... at gmail.com> wrote:
>
> > ============test.py======
> > import pydoc
> >
> > '''this is a test'''
> >
> > class A(object):
> > '''docstring'''
> > pass
> >
> > print(pydoc.help(__file__[:-3]))
> > =============
> >
> > python test.py
>
>
> OK that works, but only if I cd into the folder of the script. If I
> run it from ~ I get the same error. How to get around that prob?
>
> -- Gnarlie
=======
import pydoc
import os
import sys
'''this is a test'''
class A(object):
'''docstring'''
pass
_path, _file_name = os.path.split(__file__)
_module_name = _file_name[:-3]
sys.path.append(_path)
pydoc.help(_module_name)
=====
Note: I've included an underscore in variables names so that they would not appear.
Note 2: for some reason, which I do not understand, it shows the help twice (i.e. I have to hit "q" twice to make it go away). Sorry that I can not help with this.
André
More information about the Python-list
mailing list