1. sys模块
import sys
https://docs.python.org/2/library/sys.html?highlight=sys#module-sys
sys._getframe([depth])
"Return a frame object from the call stack. If optional integer depth is given, return the frame
object that many calls below the top of the stack. If that is deeper than the call stack, ValueError
is raised. The default fordepth is zero, returning the frame at the top of the call stack."
在options.py中的使用,在OptionParser类的define方法的实现中:
1 frame = sys._getframe(0)
2. inspect 模块
https://docs.python.org/2/library/inspect.html
"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. "
该模块中包含 frame 类型(即: sys._getframe() 返回值的类型 )的说明。
3. unittest.mock.patch
mock 模块
Python中的单元测试。
4. 不了解的语法
4.1 return xxxx if yyyy else zzzz
1 def value(self):
2 return self.default if self._value is _Option.UNSET else self._value 4.2 xxx for yyy, zzz in ttt
1 _TIMEDELTA_ABBREV_DICT = dict(
2 (abbrev, full) for full, abbrevs in _TIMEDELTA_ABBREVS
3 for abbrev in abbrevs) 4.3 正则表达式