Python 批量抓取help()函数的帮助内容(附36M帮助文档)

 在python提示符下,help(int)可以得到 class int 的帮助; help("math") 可以得到 built-in module math 的帮助;...等等

>>> help(int)
Help on class int in module builtins:

class int(object)
 |  int([x]) -> 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
 |  
 |  Built-in subclasses:
 |      bool
 |  
 |  Methods defined here:
 |  
 |  __abs__(self, /)
 |      abs(self)
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __and__(self, value, /)
 |      Return self&value.
 |  
 |  __bool__(self, /)
 |      self != 0
 |  
 |  __ceil__(...)
 |      Ceiling of an Integral returns itself.
 |  
 |  __divmod__(self, value, /)
 |      Return divmod(self, value).
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __float__(self, /)
 |      float(self)
 |  
 |  __floor__(...)
 |      Flooring an Integral returns itself.
 |  
 |  __floordiv__(self, value, /)
 |      Return self//value.
 |  
 |  __format__(self, format_spec, /)
 |      Default object formatter.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __getnewargs__(self, /)
 |  
 |  __gt__(self, value, /)
 |      Return self>value.
 |  
 |  __hash__(self, /)
 |      Return hash(self).
 |  
 |  __index__(self, /)
 |      Return self converted to an integer, if self is suitable for use as an index into a list.
 |  
 |  __int__(self, /)
 |      int(self)
 |  
 |  __invert__(self, /)
 |      ~self
 |  
 |  __le__(self, value, /)
 |      Return self<=value.
 |  
 |  __lshift__(self, value, /)
 |      Return self<<value.
 |  
 |  __lt__(self, value, /)
 |      Return self<value.
 |  
 |  __mod__(self, value, /)
 |      Return self%value.
 |  
 |  __mul__(self, value, /)
 |      Return self*value.
 |  
 |  __ne__(self, value, /)
 |      Return self!=value.
 |  
 |  __neg__(self, /)
 |      -self
 |  
 |  __or__(self, value, /)
 |      Return self|value.
 |  
 |  __pos__(self, /)
 |      +self
 |  
 |  __pow__(self, value, mod=None, /)
 |      Return pow(self, value, mod).
 |  
 |  __radd__(self, value, /)
 |      Return value+self.
 |  
 |  __rand__(self, value, /)
 |      Return value&self.
 |  
 |  __rdivmod__(self, value, /)
 |      Return divmod(value, self).
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __rfloordiv__(self, value, /)
 |      Return value//self.
 |  
 |  __rlshift__(self, value, /)
 |      Return value<<self.
 |  
 |  __rmod__(self, value, /)
 |      Return value%self.
 |  
 |  __rmul__(self, value, /)
 |      Return value*self.
 |  
 |  __ror__(self, value, /)
 |      Return value|self.
 |  
 |  __round__(...)
 |      Rounding an Integral returns itself.
 |      Rounding with an ndigits argument also returns an integer.
 |  
 |  __rpow__(self, value, mod=None, /)
 |      Return pow(value, self, mod).
 |  
 |  __rrshift__(self, value, /)
 |      Return value>>self.
 |  
 |  __rshift__(self, value, /)
 |      Return self>>value.
 |  
 |  __rsub__(self, value, /)
 |      Return value-self.
 |  
 |  __rtruediv__(self, value, /)
 |      Return value/self.
 |  
 |  __rxor__(self, value, /)
 |      Return value^self.
 |  
 |  __sizeof__(self, /)
 |      Returns size in memory, in bytes.
 |  
 |  __sub__(self, value, /)
 |      Return self-value.
 |  
 |  __truediv__(self, value, /)
 |      Return self/value.
 |  
 |  __trunc__(...)
 |      Truncating an Integral returns itself.
 |  
 |  __xor__(self, value, /)
 |      Return self^value.
 |  
 |  as_integer_ratio(self, /)
 |      Return integer ratio.
 |      
 |      Return a pair of integers, whose ratio is exactly equal to the original int
 |      and with a positive denominator.
 |      
 |      >>> (10).as_integer_ratio()
 |      (10, 1)
 |      >>> (-10).as_integer_ratio()
 |      (-10, 1)
 |      >>> (0).as_integer_ratio()
 |      (0, 1)
 |  
 |  bit_length(self, /)
 |      Number of bits necessary to represent self in binary.
 |      
 |      >>> bin(37)
 |      '0b100101'
 |      >>> (37).bit_length()
 |      6
 |  
 |  conjugate(...)
 |      Returns self, the complex conjugate of any int.
 |  
 |  to_bytes(self, /, length, byteorder, *, signed=False)
 |      Return an array of bytes representing an integer.
 |      
 |      length
 |        Length of bytes object to use.  An OverflowError is raised if the
 |        integer is not representable with the given number of bytes.
 |      byteorder
 |        The byte order used to represent the integer.  If byteorder is 'big',
 |        the most significant byte is at the beginning of the byte array.  If
 |        byteorder is 'little', the most significant byte is at the end of the
 |        byte array.  To request the native byte order of the host system, use
 |        `sys.byteorder' as the byte order value.
 |      signed
 |        Determines whether two's complement is used to represent the integer.
 |        If signed is False and a negative integer is given, an OverflowError
 |        is raised.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods defined here:
 |  
 |  from_bytes(bytes, byteorder, *, signed=False) from builtins.type
 |      Return the integer represented by the given array of bytes.
 |      
 |      bytes
 |        Holds the array of bytes to convert.  The argument must either
 |        support the buffer protocol or be an iterable object producing bytes.
 |        Bytes and bytearray are examples of built-in objects that support the
 |        buffer protocol.
 |      byteorder
 |        The byte order used to represent the integer.  If byteorder is 'big',
 |        the most significant byte is at the beginning of the byte array.  If
 |        byteorder is 'little', the most significant byte is at the end of the
 |        byte array.  To request the native byte order of the host system, use
 |        `sys.byteorder' as the byte order value.
 |      signed
 |        Indicates whether two's complement is used to represent the integer.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  denominator
 |      the denominator of a rational number in lowest terms
 |  
 |  imag
 |      the imaginary part of a complex number
 |  
 |  numerator
 |      the numerator of a rational number in lowest terms
 |  
 |  real
 |      the real part of a complex number

 可以用以下代码,批量抓取帮助文档,部分文档的内容很有学习参考价值。

import sys

str=["int","float","complex","str","array","list","tuple","set","dict",
     "math","cmath","random","sys","os","json","pickle","shelve","xml",
     "re","logging","getpass","subprocess","hashlib","shutil","time",
     "datetime","configparser","traceback","itertools",
     "openpyxl","pyautogui","pymysql","numpy","pandas","scipy","six",
     "matplotlib","pybrain","ipython","seaborn","anaconda","yaml",
     "esptool","jupyter","sympy","markupsafe","pymsgbox","mouseifo",
     "win32api","win32con","win32gui","help"]

i = 0
out = sys.stdout #保存标准输出流

for s in str:
    i += 1
    fn = "help" + ("%03d" % i) + "_" + s + ".txt"
    f=open(fn, 'w')
    sys.stdout = f
    help(s)
    f.close()

sys.stdout = out #恢复标准输出流

print("end")

帮助文档清单:

E:\Python>dir help*
 驱动器 E 中的卷没有标签。
 卷的序列号是 000D-8746

 E:\Python 的目录

2021/03/24 周三  23:23              7,376 help001_int.txt
2021/03/24 周三  23:23              5,393 help002_float.txt
2021/03/24 周三  23:23              3,055 help003_complex.txt
2021/03/24 周三  23:23            15,060 help004_str.txt
2021/03/24 周三  23:23            18,132 help005_array.txt
2021/03/24 周三  23:23              3,730 help006_list.txt
2021/03/24 周三  23:23              2,026 help007_tuple.txt
2021/03/24 周三  23:23              4,323 help008_set.txt
2021/03/24 周三  23:23              3,891 help009_dict.txt
2021/03/24 周三  23:23              8,109 help010_math.txt
2021/03/24 周三  23:23              2,949 help011_cmath.txt
2021/03/24 周三  23:23            25,506 help012_random.txt
2021/03/24 周三  23:23            15,424 help013_sys.txt
2021/03/24 周三  23:23            51,197 help014_os.txt
2021/03/24 周三  23:23            24,838 help015_json.txt
2021/03/24 周三  23:23            21,188 help016_pickle.txt
2021/03/24 周三  23:23            18,570 help017_shelve.txt
2021/03/24 周三  23:23              1,225 help018_xml.txt
2021/03/24 周三  23:23            18,428 help019_re.txt
2021/03/24 周三  23:23            51,018 help020_logging.txt
2021/03/24 周三  23:23              3,728 help021_getpass.txt
2021/03/24 周三  23:23            22,244 help022_subprocess.txt
2021/03/24 周三  23:23            14,001 help023_hashlib.txt
2021/03/24 周三  23:23            23,320 help024_shutil.txt
2021/03/24 周三  23:23            11,092 help025_time.txt
2021/03/24 周三  23:23            21,670 help026_datetime.txt
2021/03/24 周三  23:23            79,356 help027_configparser.txt
2021/03/24 周三  23:23            18,562 help028_traceback.txt
2021/03/24 周三  23:23            20,645 help029_itertools.txt
2021/03/24 周三  23:23                 942 help030_openpyxl.txt
2021/03/24 周三  23:23            50,019 help031_pyautogui.txt
2021/03/24 周三  23:23            83,204 help032_pymysql.txt
2021/03/24 周三  23:23       2,573,280 help033_numpy.txt
2021/03/24 周三  23:23              3,354 help034_pandas.txt
2021/03/24 周三  23:23       1,866,667 help035_scipy.txt
2021/03/24 周三  23:23            21,210 help036_six.txt
2021/03/24 周三  23:23            24,818 help037_matplotlib.txt
2021/03/24 周三  23:23                   73 help038_pybrain.txt
2021/03/24 周三  23:23                 139 help039_ipython.txt
2021/03/24 周三  23:23                 733 help040_seaborn.txt
2021/03/24 周三  23:23                 140 help041_anaconda.txt
2021/03/24 周三  23:23            13,057 help042_yaml.txt
2021/03/24 周三  23:23          187,145 help043_esptool.txt
2021/03/24 周三  23:23                 200 help044_jupyter.txt
2021/03/24 周三  23:23     30,978,676 help045_sympy.txt
2021/03/24 周三  23:23            20,481 help046_markupsafe.txt
2021/03/24 周三  23:23              1,705 help047_pymsgbox.txt
2021/03/24 周三  23:23                 140 help048_mouseifo.txt
2021/03/24 周三  23:23            10,124 help049_win32api.txt
2021/03/24 周三  23:23          129,227 help050_win32con.txt
2021/03/24 周三  23:23            13,720 help051_win32gui.txt
2021/03/24 周三  23:23          126,032 help052_help.txt
2021/03/24 周三  23:24          833,031 help_Python.rar
              53 个文件     37,454,173 字节
               0 个目录 162,196,828,160 可用字节

E:\Python>

共52个文本文件,约36M;其中sympy库的帮助最牛,一个文件就30M;全部文本文件的打包后只有833K,已上传本站资源,只要2个下载积分欢迎下载。

下载地址:  https://download.csdn.net/download/boysoft2002/16085212

猜你喜欢

转载自blog.csdn.net/boysoft2002/article/details/115190848