Python Forum
Pydoc documentation doesnt work - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Pydoc documentation doesnt work (/thread-23141.html)



Pydoc documentation doesnt work - Cosmosso - Dec-12-2019

I keep trying to make a html documentation file with pydoc .

I run my code in Python IDLE Shell and then use this:

import <your module name> as name:
import pydoc
pydoc.writeDoc(name)
But it doesn't work at all. I don't get a .html documentation file of my program.
Could someone help?

I have also tried this:

pydoc -w myModule.py
in IDLE and it also did not work.


RE: Pydoc documentation doesnt work - Gribouillis - Dec-12-2019

Try
Output:
pydoc -w myModule
in an ordinary terminal (not in the python console). Don't include the ".py" suffix in the module's name.


RE: Pydoc documentation doesnt work - Cosmosso - Dec-13-2019

(Dec-12-2019, 11:26 PM)Gribouillis Wrote: Try
Output:
pydoc -w myModule
in an ordinary terminal (not in the python console). Don't include the ".py" suffix in the module's name.

Ive tried it in in cmd and also in Python terminal. It didnt work.


RE: Pydoc documentation doesnt work - Gribouillis - Dec-13-2019

What happens if you type in a Cmd terminal
Output:
pydoc -b
?


RE: Pydoc documentation doesnt work - Cosmosso - Dec-13-2019

(Dec-13-2019, 06:59 AM)Gribouillis Wrote: What happens if you type in a Cmd terminal
Output:
pydoc -b
?

I have figured it out. It works now. Thank you for your help aswell and for your time.

The problem for me was that I would open the file as Edit With IDLE (by clicking on the .py file with right mouse click), but when I tried opening the program using File->Open in IDLE Shell it seemed to work fine.


RE: Pydoc documentation doesnt work - vidito - Nov-25-2023

I'm glad you figured it out. For others who might be interested:

PyDoc reads and generates documentation based on the docstrings you have written in your code. Docstrings are just comments enclosed in triple quotes that tell others what the code does, what the parameters are or what the function returns.
I suggest two ways to do that:

One way to generate an HTML documentation from inside your code editor, is to just import pydoc and at the end use pydoc.writedoc('name_of_my_module') . This generates name_of_my_module.html in the same directory.

import pydoc

def add(x, y):
    """
    Params:
      x and b are numbers (int or float)
    Returns: 
      the sum of x and y.
    """
    return x + y

pydoc.writedoc('my_module')
Alternatively, you can remove the import pydoc and the last line and instead use command line by using python -m pydoc -w my_module

To learn more you can read the following article: https://pythonology.eu/how-to-use-pydoc-to-generate-documentation-in-python/