最好的方法一般是
①import 对应模块
②print(模块名.doc) #调出模块文档
③dir(模块名) #查看模块参数、函数、类
④模块名.all #过滤不需要的属性,显示这个模块供调用的所有东西。
如果没有设置__all__属性的话,import 模块名 as *这一操作会把所有不以下划线开头名字都导入到当前命名空间。建议在编写模块的时候,对外提供接口函数和类,都设置到__all__这一个列表里面。
⑤模块名.file #返回模块名文件的路径
⑥help(模块名) #综上得出的帮助文档
>>> import timeit
>>> timeit.__doc__
"Tool for measuring execution time of small code snippets.\n\nThis module avoids a number of common traps for measuring execution\ntimes. See also Tim Peters' introduction to the Algorithms chapter in\nthe Python Cookbook, published by O'Reilly.\n\nLibrary usage: see the Timer class.\n\nCommand line usage:\n python timeit.py [-n N] [-r N] [-s S] [-p] [-h] [--] [statement]\n\nOptions:\n -n/--number N: how many times to execute 'statement' (default: see below)\n -r/--repeat N: how many times to repeat the timer (default 5)\n -s/--setup S: statement to be executed once initially (default 'pass').\n Execution time of this setup statement is NOT timed.\n -p/--process: use time.process_time() (default is time.perf_counter())\n -v/--verbose: print raw timing results; repeat for more digits precision\n -u/--unit: set the output time unit (nsec, usec, msec, or sec)\n -h/--help: print this usage message and exit\n --: separate options from statement, use when statement starts with -\n statement: statement to be timed (default 'pass')\n\nA multi-line statement may be given by specifying each line as a\nseparate argument; indented lines are possible by enclosing an\nargument in quotes and using leading spaces. Multiple -s options are\ntreated similarly.\n\nIf -n is not given, a suitable number of loops is calculated by trying\nincreasing numbers from the sequence 1, 2, 5, 10, 20, 50, ... until the\ntotal time is at least 0.2 seconds.\n\nNote: there is a certain baseline overhead associated with executing a\npass statement. It differs between versions. The code here doesn't try\nto hide it, but you should be aware of it. The baseline overhead can be\nmeasured by invoking the program without arguments.\n\nClasses:\n\n Timer\n\nFunctions:\n\n timeit(string, string) -> float\n repeat(string, string) -> list\n default_timer() -> float\n\n"
>>> print(timeit.__doc__)
Tool for measuring execution time of small code snippets.
This module avoids a number of common traps for measuring execution
times. See also Tim Peters' introduction to the Algorithms chapter in
the Python Cookbook, published by O'Reilly.
Library usage: see the Timer class.
Command line usage:
python timeit.py [-n N] [-r N] [-s S] [-p] [-h] [--] [statement]
Options:
-n/--number N: how many times to execute 'statement' (default: see below)
-r/--repeat N: how many times to repeat the timer (default 5)
-s/--setup S: statement to be executed once initially (default 'pass').
Execution time of this setup statement is NOT timed.
-p/--process: use time.process_time() (default is time.perf_counter())
-v/--verbose: print raw timing results; repeat for more digits precision
-u/--unit: set the output time unit (nsec, usec, msec, or sec)
-h/--help: print this usage message and exit
--: separate options from statement, use when statement starts with -
statement: statement to be timed (default 'pass')
A multi-line statement may be given by specifying each line as a
separate argument; indented lines are possible by enclosing an
argument in quotes and using leading spaces. Multiple -s options are
treated similarly.
If -n is not given, a suitable number of loops is calculated by trying
increasing numbers from the sequence 1, 2, 5, 10, 20, 50, ... until the
total time is at least 0.2 seconds.
Note: there is a certain baseline overhead associated with executing a
pass statement. It differs between versions. The code here doesn't try
to hide it, but you should be aware of it. The baseline overhead can be
measured by invoking the program without arguments.
Classes:
Timer
Functions:
timeit(string, string) -> float
repeat(string, string) -> list
default_timer() -> float
>>> dir(timeit)
['Timer', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_globals', 'default_number', 'default_repeat', 'default_timer', 'dummy_src_name', 'gc', 'itertools', 'main', 'reindent', 'repeat', 'sys', 'template', 'time', 'timeit']
>>> timeit.__all__
['Timer', 'timeit', 'repeat', 'default_timer'] #前面文档有说明,第一个是类,后三个是函数。
>>> import timeit
>>> timeit.__file__ #找到该模块的文件路径
'D:\\python\\lib\\timeit.py'