0

I have a project in Django and I write docstrings in my modules, classes and functions. But I need a way to extract all __doc__ from there automatically. Like "python manage.py collectstatic" but for .__doc__ instances for all .py codes. Something like that? Some ideas?

mzjn
  • 48,958
  • 13
  • 128
  • 248
pydev
  • 1
  • 2
  • 1
    You're probably looking for [pydoc](https://docs.python.org/3/library/pydoc.html) – solarissmoke Sep 29 '18 at 04:32
  • 2
    if you are looking for pydoc(and it sounds like you are.) I would recommend investing the extra effort to get sphinx working ... you will not regret it – Joran Beasley Sep 29 '18 at 04:49

1 Answers1

1

Giving you a glimpse of pydoc

Example module:

# foo.py

def bar():
  """this is the docstring for bar()"""
  print 'hello'


def baz():
  """this is the docstring for baz()"""
  print 'world'

Now you can print the docstrings using below command:

$ pydoc foo.py
Help on module foo:

NAME
    foo

FILE
    /path/to/foo.py

FUNCTIONS
    bar()
        this is the docstring for bar()

    baz()
        this is the docstring for baz()

You can also generate an HTML help file:

$ pydoc -w ./foo.py
wrote foo.html

which looks like this:

enter image description here

Vishvajit Pathak
  • 3,351
  • 1
  • 21
  • 16
  • Yes, pydoc is util. But in Python 3 not so much. The imports, for example, have conflicts with the pydoc. The text encoding too. – pydev Oct 06 '18 at 02:19