您的位置:首页 > 编程语言 > Python开发

[Python]回顾Python中的内省机制

2016-02-13 19:21 615 查看

学习资源

http://zetcode.com/lang/python/introspection/

http://www.ibm.com/developerworks/library/l-pyint/index.html

http://www.diveintopython.net/power_of_introspection/index.html

/article/5268066.html

内省(Introspection) 是什么?

在计算机科学中,内省指一种能力,可以确定对象是什么,包含何种信息,可以做什么。

Python 就是一门提供了内省机制的语言。

Python 的内省机制

help 函数

sys 模块

sys模块中包含了系统,当前进程等相关的信息,例如

sys.platform
sys.version
sys.maxint
sys.arg
sys.path
sys.modules


keyword模块

keyword.kwlist 包含Python所有的关键词

>>> import keyword
>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']


dir函数

返回由传入对象的属性排序后构成的列表

builtins模块

包含Python中的内建函数

docstring

__name__
属性

hasattr函数

getattr函数

type函数

id函数

callable函数

isinstance函数

issubclass函数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: