pydoc is a document generation module built into python.
pydoc The module automatically generates documentation based on the Python module. The generated documentation can be displayed as a text page in the console, made available to a web browser, or saved as an HTML file.
For modules, classes, functions, and methods, the content of the displayed documentation is taken from the documentation string (i.e., the__doc__
attribute) and will recursively fetch it from its documented member. If there is no document string, thepydoc will try to get it from the comment line paragraph above the class, function, or method definition, or at the top of the module (see the()).
built-in functionhelp() will initiate a call to the interactive interpreter's online help system, which uses thepydoc Generate the contents of a document in text form on the terminal. The same textual documentation can also be scripted outside of the Python interpreter by running it at the operating system's command promptpydoc to view it. For example, running
python -m pydoc sys
The output is as follows:
Help on built-in module sys: NAME sys MODULE REFERENCE /3.11/library/ -- More --
At the terminal prompt, you will be prompted by thesys module displays document content in a style similar to the Unixman The guide page displayed by the command.pydoc argument can be a function, module, package, or a reference with a dot to a class, method, or function in a module and a module in a package. If passed topydoc argument looks like a path (i.e., it contains the path separator for the operating system it is on, such as a forward slash for Unix) and it points to an existing Python source file, then the documentation is generated for that file.
Note: In order to find the object and its document contents, thepydoc The module where the document is located will be imported. Therefore, any module-level code will be executed. Please use theif __name__ == '__main__':
statement to ensure that a file's specific code is executed only when it is initiated as a script call and not when it is imported.
When the printout goes to the console, thepydoc will attempt to page the output for easier reading. If you set thePAGER
environment variables.pydoc The variable value will be used as the paging program.
Precede the parameter with-w
Instead of displaying the text in the console, the banner will write the HTML document to a file in the current directory.
Precede the parameter with-k
The flag will search the synopsis lines of all available modules for the keyword given by the parameter, again in a manner similar to the Unixman command. The synopsis line of a module is the first line of its documentation string.
You can also use thepydoc Starts an HTTP server on the local machine and presents the document to a visiting web browser.python -m pydoc -p 1234 will start an HTTP server on port 1234, which will allow you to use it in your web browser via thehttp://localhost:1234/
to view the document. Specify the0
as the port number will arbitrarily select an unused port.
python -m pydoc -n <hostname> will start the server listening on the given hostname. The default hostname is 'localhost' but if you want to be able to search for that server from other machines, you may want to change the hostname that the server responds to. This feature is particularly useful in the development phase, if you want to run pydoc in a container.
python -m pydoc -b This will start the server and open an additional web browser to access the Module Index page. Each published page has a navigation bar at the top, where you can click Get to get help for a specific entry, Search to search for a keyword in the summary line of all modules, or Module index, Topics and Keywords to go to the corresponding page.
Open the generated api document in your local browser:
python -m pydoc -p 1234 -b
When generated it will start a web server locally:
(venv) PS H:\beta (software)\requests-main> python -m pydoc -p 1234 -b Server ready at http://localhost:1234/ Server commands: [b]rowser, [q]uit server>
(coll.) fail (a student)pydoc When generating document content, it uses the current environment and path to locate the module. Therefore, initiating a call topydoc spam The resulting version of the documentation will be the same as if you had started the Python interpreter and typedimport spam
The version of the module you get is exactly the same.
The module documentation location for the core module corresponds to the//library/
included among theseX
cap (a poem)Y
are the major and minor version numbers of the Python interpreter. This can be done by setting thePYTHONDOCS
environment variable to be overridden to point to a different URL or local directory containing a Library Reference Manual page.
to this article on python pydoc to generate API documentation on the implementation of the article is introduced to this, more related python pydoc to generate API documentation content, please search for my previous articles or continue to browse the following related articles I hope that you will support me more in the future!