Following on "Windows 7 - pydoc from cmd", I have the following problem. I prepared a simple, docstring-documented hello.py "hello world" script:
""" This module prints Hello, world
More documentation.
"""
print("Hello, world")
and saved it in C:\Python34\lib.
Then using Window's command-line, I changed the directory to C:\Python34\lib, and ran
pydoc <full path to hello.py>
My output is:
Hello, world
Help on module hello:
NAME
hello
DESCRIPTION
This module prints Hello, world
More documentation.
FILE
c:\python34\lib\hello.py
It's great that it printed the documentation, but first it ran the program.
How do I get it to NOT run the program, just print the documentation?
Get out of pydoc by typing q to quit.
Pydoc is the documentation generation system for Python. Say you can document your functions using the Pydoc standard and then it can be used to generate documentation in your code. Follow this answer to receive notifications.
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.
You can add raw_input('Press Enter to exit') right before your program would exit. It tells Python to wait for input before exiting.
pydoc
imports the module to be documented. So statements there are executed.
If you can modify the code, guard the print
line with if __name__ == "__main__"
so the line is executed only when it is executed directly, but not when it is imported:
""" This module prints Hello, world
More documentation.
"""
if __name__ == "__main__":
print("Hello, world")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With