Object introspection
Object introspection
Introspection: the ability to determine the type of an object at runtime.
One of Python’s strengths.
Everything in Python is an object and we can examine those objects.
dir
dir
Returns a list of attributes and methods belonging to an object. Here is an example:
Introspection gave us the names of all the methods of a list.
dir()
without any argument then it returns all names in the current scope.
type
and id
type
and id
type
function returns the type of an object.
Example:
id
returns the unique ids of various objects.
Example:
inspect
module
inspect
moduleProvides several useful functions to get information about live objects.
Example: check the members of an object by running:
Last updated