Reading python documentation in the terminal?

后端 未结 6 797
谎友^
谎友^ 2020-12-30 12:14

Is there a way to install the python documentation that would make it available as if it was a manpage? (I know you can download the sourcefiles for the documentation and re

6条回答
  •  渐次进展
    2020-12-30 13:03

    You can use help(Class-name/method-name/anything). But also using __doc__

    A special __doc__ docstring is attached to every class and method. For example look what i typed into my interpreter.

    >>> print(str.__doc__)
    str(object='') -> str
    str(bytes_or_buffer[, encoding[, errors]]) -> str
    
    Create a new string object from the given object. If encoding or
    errors is specified, then the object must expose a data buffer
    that will be decoded using the given encoding and error handler.
    Otherwise, returns the result of object.__str__() (if defined)
    or repr(object).
    encoding defaults to sys.getdefaultencoding().
    errors defaults to 'strict'.
    >>> print(int.__doc__)
    int(x=0) -> integer
    int(x, base=10) -> integer
    
    Convert a number or string to an integer, or return 0 if no arguments
    are given.  If x is a number, return x.__int__().  For floating point
    numbers, this truncates towards zero.
    
    If x is not a number or if base is given, then x must be a string,
    bytes, or bytearray instance representing an integer literal in the
    given base.  The literal can be preceded by '+' or '-' and be surrounded
    by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
    Base 0 means to interpret the base from the string as an integer literal.
    >>> int('0b100', base=0)
    4
    

    It even works for modules.

    >>> import math
    >>> math.__doc__
    'This module is always available.  It provides access to the\nmathematical functions defined by the C standard.'
    >>> math.ceil.__doc__
    'ceil(x)\n\nReturn the ceiling of x as an Integral.\nThis is the smallest integer >= x.'
    >>> 
    

    Since every class has a __doc__ which is a docstring attached to it you can call it using the class_name.__doc__

    >>> print(ord.__doc__)
    Return the Unicode code point for a one-character string.
    

提交回复
热议问题