Write documentation of a library in a txt

1

The idea is basically to pass all the documentation to a txt

import socket

archivo=('sockets.txt','w')

archivo.write(help(socket))

archivo.close()
    
asked by Diego 21.06.2017 в 00:45
source

1 answer

1

I do not know what reason you have to do this, if by any chance you want to have the complete documentation of Python offline, you can download from the official website . You have it in EPUB, PDF, HTML and plain text.

That said, you can do what you want by using pydoc to generate the documentation and get a string. You just have to save that string in the txt:

import pydoc

biblioteca = 'socket'

str_doc = pydoc.render_doc(biblioteca, renderer=pydoc.plaintext)

with open(biblioteca+'.txt', 'w') as f:
    f.write(str_doc)

This creates a nice txt that starts like this:

Python Library Documentation: module socket

NAME
    socket

DESCRIPTION
    This module provides socket operations and some related functions.
    On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
    On other systems, it only supports IP. Functions specific for a
    socket are available as methods of the socket object.

    Functions:

    socket() -- create a new socket object
    socketpair() -- create a pair of new socket objects [*]
    fromfd() -- create a socket object from an open file descriptor [*]
    ...

The code is valid for Python 3.x, although you can follow the same idea for Python 2.x (you just have to modify the theme of the rendered argument).

    
answered by 21.06.2017 / 01:20
source