On this page
inspect.getmembers
Prev: inspect.getlineno | Up: inspect | Next: inspect.getmembers_static
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.getmembers
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import getmembers
Signature & Overview
inspect.getmembers(object, predicate=None)
Return all members of an object as (name, value) pairs sorted by name.
Usage
import inspect
import math
funcs = dict(inspect.getmembers(math, inspect.isbuiltin))
assert "sqrt" in funcs and "pi" not in funcs
Gotchas
- Invokes properties/descriptors via
getattr(): Useinspect.getmembers_static()(Python 3.11+) when inspecting objects that may have side-effecting properties.
REPL Inspect
from inspect import getmembers
help(getmembers)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/getlineno Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/getmembers_static Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BoundArguments shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClassFoundException shared tags: #inspect, #stdlib