关于python中inspect模块的一些探究
来源:互联网 发布:js上传图片到服务器 编辑:程序博客网 时间:2024/06/06 05:17
根据度娘搜到的,inspect模块主要提供了四种用处:
(1). 对是否是模块,框架,函数等进行类型检查。
(2). 获取源码
(3). 获取类或函数的参数的信息
(4). 解析堆栈
我在这次课程中,只用到了第三种用处,即获取类或函数的参数的信息,下面我来探究一下。
结合我正在学习的课程,我自己也对inspect做了一些探究。根据在课程中用到的一些函数及方法,我做了一个python脚本。
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
执行以上脚本,将得到如下输出:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
总结
inspect.signature(fn)
将返回一个inspect.Signature
类型的对象,值为fn这个函数的所有参数inspect.Signature
对象的paramerters
属性是一个mappingproxy
(映射)类型的对象,值为一个有序字典(Orderdict)。这个字典里的key是即为参数名,
str
类型这个字典里的value是一个
inspect.Parameter
类型的对象,根据我的理解,这个对象里包含的一个参数的各种信息
inspect.Parameter
对象的kind
属性是一个_ParameterKind
枚举类型的对象,值为这个参数的类型(可变参数,关键词参数,etc)inspect.Parameter
对象的default
属性:如果这个参数有默认值,即返回这个默认值,如果没有,返回一个inspect._empty
类。
原文链接:http://blog.csdn.net/weixin_35955795/article/details/53053762
阅读全文
0 0
- 关于python中inspect模块的一些探究
- 关于python中inspect模块的一些探究
- python的inspect模块
- python的inspect模块
- 关于inspect模块(Python)
- python inspect模块解析
- python inspect模块解析
- Python inspect模块学习
- python inspect模块解析
- python inspect模块解析
- python inspect模块解析
- python中inspect使用
- python inspect模块解析--提供自省功能
- 关于标签的一些探究
- Python中常用的一些模块
- Python之inspect模块实现获取加载模块路径
- python inspect
- python的decorator的一些探究
- 无Python环境变量python正常使用
- IPv6终于要取代IPv4了!阿里云将全面提供IPv6服务
- Spring MVC的web.xml配置详解(转)
- 常见问题
- HashMap和HashSet的区别
- 关于python中inspect模块的一些探究
- Linux 安装activeMq
- python爬虫提取数据之Beautifulsoup4简单使用
- Mybatis中JdbcType,JavaType和Mysql数据类型对照关系
- oracle数据库基础知识---DML
- PC-Lint使用
- 树结构列表按父子顺序排序
- mysql
- package.json字段全解