发现python有个好用的检查模块-inspect, 查看源文件发现它提供了不少好用的方法:
“”"
Here are some of the useful functions provided by this module:

ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),isroutine() – check object types

getmembers() – get members of an object that satisfy a given condition

getfile(), getsourcefile(), getsource() – find an object’s source code
getdoc(), getcomments() – get documentation on an object
getmodule() – determine the module that an object came from
getclasstree() – arrange classes so as to represent their hierarchy

getargspec(), getargvalues() – get info about function arguments
formatargspec(), formatargvalues() – format an argument spec
getouterframes(), getinnerframes() – get info about frames
currentframe() – get the current stack frame
stack(), trace() – get info about frames on the stack or in a traceback
“”"

举例:

import inspect
inspect.isbuiltin(abs)
Trueimport os
inspect.ismodule(os)
Trueclass C:pass
inspect.isclass(C)
Trueclass C(object):def foo(self):print 'here is foo'def bez(self):print 'here is bez'inspect.getmembers(C, inspect.ismethod)
[('bez', "<"unbound method C.bez">"), ('foo', "<"unbound method C.foo">")]

上面要是不加inspect.ismethod的话,会将对象的所有默认属性都列出来

其他方法就一一列举

原文:http://justpy.com/archives/tag/%E5%88%A4%E6%96%AD%E5%AF%B9%E8%B1%A1%E6%98%AF%E5%90%A6%E6%98%AF%E7%B1%BB

转载于:https://www.cnblogs.com/walkerwang/archive/2011/08/03/2125903.html

python的inspect模块相关推荐

  1. python中inspect模块用法详解

    获取函数签名对象.函数签名包含了一个函数的信息,包括函数名.它的参数类型.它所在的类和名称空间及其他信息). inspect模块主要提供了四种用处: 对是否是模块.框架.函数进行类型检查 获取源码 获 ...

  2. inspect python_Python之inspect模块实现获取加载模块路径的方法

    该文主要介绍如何获取模块的路径,需要申明的是这里所说的模块可以是功能实现的该模块,也可以是别的模块. 使用到的是 inspect 模块的 .getsourcefile(需要获取的模块名) 创建test ...

  3. python inspect模块解析

    来源:https://my.oschina.net/taisha/blog/55597 inspect模块主要提供了四种用处: (1) 对是否是模块,框架,函数等进行类型检查. (2) 获取源码 (3 ...

  4. Python自省(反射) 与 inspect 模块

    Python 自省指南:https://www.ibm.com/developerworks/cn/linux/l-pyint/ From:https://my.oschina.net/taisha/ ...

  5. Python语法学习记录(24):inspect模块介绍及常用使用方式

    1.简述 获取函数签名对象. 函数签名包含了一个函数的信息,包括函数名.它的参数类型.它所在的类和名称空间及其他信息). 2.基本用法 inspect模块主要提供了四种用处: 1.对是否是模块.框架. ...

  6. python查看模块功能_Python进阶之inspect模块使用详解

    前几篇内容我们详细探讨了如何从Python中获取帮助信息: 前情回顾 1.查看模块.类提供了哪些接口: 需要帮助吗?dir函数的孪生兄弟,Python中魔法方法__dir__详解 2.查看对象内部属性 ...

  7. python 学习汇总46:inspect 模块简介(入门基础 tcy)

    inspect 模块 2018/11/17 inspect模块主要提供了四种用处:1.对是否是模块.框架.函数进行类型检查2.获取源码3.获取类或者函数的参数信息4.解析堆栈 一.type and m ...

  8. python基础:inspect模块各函数的用法

    目录 前言 一.inspect模块总览 1.获取成员与判断 2.获取源代码 3.类与函数 4.调用栈 二.inspect模块方法的使用 1.getmembers 2.getcomments.getdo ...

  9. python inspect模块

    inspect模块的四种用处: 1)对是否是模块,框架,函数等进行类型检查 2)获取源码 3)获取类或函数的参数的信息 4)解析堆栈. inspect.stack()[1][3] #当前运行的函数的函 ...

最新文章

  1. 【FFmpeg】AVOutputFormat/AVInputFormat 成员变量 flags 总结
  2. tar方式安装oracle11g
  3. unix linux 命令参考,Unix/Linux 命令参考
  4. Spring管理的交易说明-第2部分(JPA)
  5. php列表框怎么用,PHP+Mysql+jQuery查询和列表框选择操作实例讲解
  6. [css] 用CSS实现一个轮播图
  7. R语言第十一讲 决策树与随机森林
  8. 预充电电路工作原理_LED触摸调光台灯控制电路板的工作原理
  9. 2022年“超级818汽车狂欢夜”启动,易车将携手汽车品牌共创内容营销
  10. 手机发布日期为什么保密?罗永浩这么说...
  11. solaris系统中的’format’程序
  12. Struts2零配置属性详解(2)
  13. Flask 的路由系统 FBV 与 CBV
  14. 几十个珍藏的网站,相信你会用到的
  15. CentOS 8 的安装(官方安装、清华大学开源软件镜像站、阿里云镜像、网易镜像下的安装步骤)
  16. VB中 vbp vbw frm frx log bas 等扩展名大全
  17. 第29课:AD中class,设计参数,规则的设置
  18. Scrapy爬虫框架的第一个实例(完整详细!)
  19. centos7配置时间同步
  20. 如何知道当前linux登录的是哪个终端设备

热门文章

  1. IntelliJ IDEA 问题总结之一 —— jar包、assets、maven、git
  2. spring 注入bean的两种方式
  3. 【设计模式】 桥梁模式
  4. hdu 4501 多维0-1背包
  5. JavaScript学习笔记(四十四) 装饰器
  6. 二分查找法的实现和应用汇总
  7. .net读写配置文件
  8. 【POJ2117】Electricity [tarjan 割点]
  9. NOIP2011 聪明的质监员
  10. 【读书笔记】Android的Ashmem机制学习