Inspect Module
On infoq yesterday, I saw this module mentioned in the speech of Douban architect. I am looking for a document today.
DOC: write it like this
The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, Frame Objects, and code objects.
This module provides some useful methods for objects such as modules, classes, methods, and functions. For example, it can help us check the content of the class andCodeParameters of the extraction and formatting methods.
# Coding: utf8 import inspectimport OS class test (object): "test class" "def test (Self): Self. FUC = Lambda X: X class testone (TEST): pass # Check type, module, class, method, generator, code, etc. can all print inspect. ismodule (OS) print inspect. isclass (TEST) print inspect. getdoc (TEST) print inspect. getsourcefile (TEST) # file path print inspect. getsourcelines (TEST) # code block. Each line contains one element to form an array of print inspect. getsource (TEST) # code block indent # print the module object in the global variable myglobals ={} my Globals. update (globals () Modules = [value for key, value in myglobals. items () If inspect. ismodule (value)] print modules # callable Method for viewing classes for name, value in inspect. getmembers (test, callable): Print "callable:", namefor name, value in inspect. getmembers (test (), callable): Print "instance callable:", namedef Hello (): Print inspect. stack () [0] [3] print inspect. the usage of stack () Hello () in a specific project is unknown.