很多常用的python函数或模块,经常需要查看帮助,很不方便。

在python的交互命令行下使用help()或在python文件中调用help()函数可以很方便的查看帮助。

 

一 查看所有的关键字:help("keywords")

1 Here is a list of the Python keywords.  Enter any keyword to get more help.
 2 
 3 and                 elif                import              return
 4 as                  else                in                  try
 5 assert              except              is                  while
 6 break               finally             lambda              with
 7 class               for                 not                 yield
 8 continue            from                or
 9 def                 global              pass
10 del                 if                  raise

二 其他

查看python所有的modules:help("modules")

单看python所有的modules中包含指定字符串的modules: help("modules yourstr")

查看python中常见的topics: help("topics")

查看python标准库中的module:import os.path + help("os.path")

查看python内置的类型:help("list")

查看python类型的成员方法:help("str.find") 

查看python内置函数:help("open")

 

三 例如查看copy模块帮助如下: help("copy")

1 Help on module copy:
 2 
 3 NAME
 4     copy - Generic (shallow and deep) copying operations.
 5 
 6 FILE
 7     c:\python31\lib\copy.py
 8 
 9 DESCRIPTION
10     Interface summary:
11     
12             import copy
13     
14             x = copy.copy(y)        # make a shallow copy of y
15             x = copy.deepcopy(y)    # make a deep copy of y
16     
17     For module specific errors, copy.Error is raised.
18     
19     The difference between shallow and deep copying is only relevant for
20     compound objects (objects that contain other objects, like lists or
21     class instances).
22     
23     - A shallow copy constructs a new compound object and then (to the
24       extent possible) inserts *the same objects* into it that the
25       original contains.
26     
27     - A deep copy constructs a new compound object and then, recursively,
28       inserts *copies* into it of the objects found in the original.
29     
30     Two problems often exist with deep copy operations that don't exist
31     with shallow copy operations:
32     
33      a) recursive objects (compound objects that, directly or indirectly,
34         contain a reference to themselves) may cause a recursive loop
35     
36      b) because deep copy copies *everything* it may copy too much, e.g.
37         administrative data structures that should be shared even between
38         copies
39     
40     Python's deep copy operation avoids these problems by:
41     
42      a) keeping a table of objects already copied during the current
43         copying pass
44     
45      b) letting user-defined classes override the copying operation or the
46         set of components copied
47     
48     This version does not copy types like module, class, function, method,
49     nor stack trace, stack frame, nor file, socket, window, nor array, nor
50     any similar types.
51     
52     Classes can use the same interfaces to control copying that they use
53     to control pickling: they can define methods called __getinitargs__(),
54     __getstate__() and __setstate__().  See the documentation for module
55     "pickle" for information on these methods.
56 
57 CLASSES
58     builtins.Exception(builtins.BaseException)
59         Error
60     ... ...
61 
62 FUNCTIONS
63     copy(x)
64         Shallow copy operation on arbitrary Python objects.
65         
66         See the module's __doc__ string for more info.
67     
68     deepcopy(x, memo=None, _nil=[])
69         Deep copy operation on arbitrary Python objects.
70         
71         See the module's __doc__ string for more info.
72 
73 DATA
74     __all__ = ['Error', 'copy', 'deepcopy']