Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pydoc not seeing docstrings?

Tags:

python

pydoc

Obviously I am missing something serious here. Here is my test program:

"""
Doc and nothing but doc
"""

class TestMe(object):
    """
    class documentation goes here
    """
    def testFunc(self):
        """
        FunctionDoc Goes here
        """
        print "Hello world"

if __name__ =="__main__":
    t=TestMe()
    t.testFunc()

I run it and it prints "Hello world", natch. But pydoc.py test.py gives this:

no Python documentation found for 'test.py'

Obviously I am missing something simple here, but what?

--edit-- Per Vishnu's suggestion I added "print t.__doc__" to the last line of the file and now running the file gives this:

Hello world

    class documentation goes here

But pydoc still does not find any documentation.

like image 989
Skip Huffman Avatar asked Nov 26 '14 13:11

Skip Huffman


People also ask

Where does Python put docstrings?

Declaring Docstrings: The docstrings are declared using ”'triple single quotes”' or “””triple double quotes””” just below the class, method or function declaration. All functions should have a docstring.

How do you access a Docstring in Python?

As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in Example 1). They are used to document our code. We can access these docstrings using the __doc__ attribute.

How do I run pydoc in terminal?

You can access the interactive shell in pydoc using it's help function. In order to do this, launch your terminal, and enter the python interactive shell. Now, import pydoc and then use the pydoc. help() command to launch the interactive shell.

What does pydoc input do?

The pydoc module automatically generates documentation from Python modules. The documentation can be presented as pages of text on the console, served to a web browser, or saved to HTML files.


1 Answers

Pydoc wants a module name, not a file name. Try pydoc test.

It will use the argument as a file name if it has a slash in it: pydoc ./test.py

like image 93
Ned Batchelder Avatar answered Sep 27 '22 19:09

Ned Batchelder