Check whether an object exposes an attribute or method using normal DSL attribute lookup. Does not call methods.
Syntax
hasattr(object, name, /)Parameters
| Name | Description |
|---|---|
objectAny | Object or namespace to check. Required · Positional only No default |
nameString | Attribute or method name. A non-string raises TypeError. Required · Positional only No default |
Returns
Boolean — True when the attribute exists, even if its value is None, False or 0. False only when it is missing; other lookup errors propagate. Dict keys follow the DSL's dot access rules.Example
# Read a coordinate only when it is available
value = Point(10, 20)
if hasattr(value, "x"):
print(value.x)
print(hasattr(value, "missing"))