Use import inspect to view the parameters and modules, function code of the Python class
The file is the smallest module, the folder is the larger module.
The file can contain classes, functions.
A function can perform an operation where multiple functions can be written as a module, written in a class based on different things, which contains several functions written in several classes, and can be used as a file.
The main step is to set the file path to the system, introduce the file as a module, and start looking at the contents of the file.
First, a function was written
def H (): print " hello " def HM (M,K): print M, K class W (object): def __init__ (A, self): name =a def g (self): print Name, "Hello world!
Save in Path \ c under, a name called hello.py
Open the Python Shell window and add the path to the system path. The command is as follows
Import Sys
Sys.path.append (' c:/')
Introduce the file as a module.
Import Hello
Import Inspect
View the entire module Hello source code: Inspect.getsource (Hello) The whole look is not good, need print inspect.getsource (hello)
View module Hello inside wo All code for this class print Inspect.getsource (HELLO.W)
To view the code for a function within a module: print Inspect.getsource (hello.h)
To view the code for a function in a class within a module print Inspect.getsource (HELLO.W.G)
Code to view the parameters of a function in a module: Inspect.getargspec (HELLO.HM)
View the parameter code inspect.getargspec (hello.w.__init__) #这里还是查看类的初始定义函数 of the class in the module.
View the function parameter code inspect.getargspec (HELLO.W.G) in the class
View module path Inspect.getabsfile (hello)
View the path of a class in a folder module Inspect.getabsfile (... ) #结果是显示类的初始定义函数__init__ the location of the. Py.
>>> inspect.getabsfile (django.db) ' C:\\python27\\lib\\site-packages\\django-1.7.1-py2.7.egg\\django\\db \\__init__.py '
These should be enough for study. What can be added later.
Python uses inspect to view code parameters