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?
pydoc(and a number of other auto-documentation tools e.g.sphinx) import the source and look for the__doc__attributes that python adds to classes/functions, etc. The only tool that I know of which doesn't import the source isepydoc. That said, usually you can guard any statements that you don't want to execute in anif __name__ == '__main__':block.