《Python编程的术与道:Python语言进阶》视频课程
《Python编程的术与道:Python语言进阶》视频课程链接:https://edu.csdn.net/course/detail/28618
代码内省 (Code Introspection)
代码内省是检查类、函数等以了解它们是什么、做什么以及知道什么的能力。
内省是一种自我检查(self examination)的行为。内省是在运行时确定对象的类型或属性的能力。 Python中的所有内容都是一个对象。 Python中的每个对象都可以具有属性和方法。 通过使用内省, 可以动态检查Python对象。
Python提供了一些用于代码内省的函数和实用程序。
函数 | 描述 |
---|---|
help() | It is used it to find what other functions do |
hasattr() | Checks if an object has an attribute |
getattr() | Returns the contents of an attribute if there are some. |
repr() | Return string representation of object |
callable() | Checks if an object is a callable object (a function) or not. |
issubclass() | Checks if a specific cla |