On this page
  1. getattr
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

getattr

Prev: frozenset | Up: __builtins__ | Next: globals
Rel: callable, delattr, dir, hasattr, hash
Ref: docs.python.org — getattr
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import getattr

Overview & Signature

getattr(object, name[, default]) -> value

Get a named attribute from an object.

Usage

assert getattr("hello", "upper")() == "HELLO"
assert getattr("hello", "missing", "default") == "default"

Gotchas

REPL Inspect

help(getattr)

Linked from

Related notes