3.11.1 Types and members

The getmembers() function retrieves the members of an object such as a class or module. The nine functions whose names begin with ``is'' are mainly provided as convenient choices for the second argument to getmembers(). They also help you determine when you can expect to find the following special attributes:

Type  Attribute  Description 
module __doc__ documentation string
  __file__ filename (missing for built-in modules)
class __doc__ documentation string
  __module__ name of module in which this class was defined
method __doc__ documentation string
  __name__ name with which this method was defined
  im_class class object in which this method belongs
  im_func function object containing implementation of method
  im_self instance to which this method is bound, or None
function __doc__ documentation string
  __name__ name with which this function was defined
  func_code code object containing compiled function bytecode
  func_defaults tuple of any default values for arguments
  func_doc (same as __doc__)
  func_globals global namespace in which this function was defined
  func_name (same as __name__)
traceback tb_frame frame object at this level
  tb_lasti index of last attempted instruction in bytecode
  tb_lineno current line number in Python source code
  tb_next next inner traceback object (called by this level)
frame f_back next outer frame object (this frame's caller)
  f_builtins built-in namespace seen by this frame
  f_code code object being executed in this frame
  f_exc_traceback traceback if raised in this frame, or None
  f_exc_type exception type if raised in this frame, or None
  f_exc_value exception value if raised in this frame, or None
  f_globals global namespace seen by this frame
  f_lasti index of last attempted instruction in bytecode
  f_lineno current line number in Python source code
  f_locals local namespace seen by this frame
  f_restricted 0 or 1 if frame is in restricted execution mode
  f_trace tracing function for this frame, or None
code co_argcount number of arguments (not including * or ** args)
  co_code string of raw compiled bytecode
  co_consts tuple of constants used in the bytecode
  co_filename name of file in which this code object was created
  co_firstlineno number of first line in Python source code
  co_flags bitmap: 1=optimized | 2=newlocals | 4=*arg | 8=**arg
  co_lnotab encoded mapping of line numbers to bytecode indices
  co_name name with which this code object was defined
  co_names tuple of names of local variables
  co_nlocals number of local variables
  co_stacksize virtual machine stack space required
  co_varnames tuple of names of arguments and local variables
builtin __doc__ documentation string
  __name__ original name of this function or method
  __self__ instance to which a method is bound, or None

getmembers (object[, predicate])
Return all the members of an object in a list of (name, value) pairs sorted by name. If the optional predicate argument is supplied, only members for which the predicate returns a true value are included.

ismodule (object)
Return true if the object is a module.

isclass (object)
Return true if the object is a class.

ismethod (object)
Return true if the object is a method.

isfunction (object)
Return true if the object is a Python function or unnamed (lambda) function.

istraceback (object)
Return true if the object is a traceback.

isframe (object)
Return true if the object is a frame.

iscode (object)
Return true if the object is a code.

isbuiltin (object)
Return true if the object is a built-in function.

isroutine (object)
Return true if the object is a user-defined or built-in function or method.

See About this document... for information on suggesting changes.