Skip to main content

DictAttribute

Dict interface to attributes.

Attributes

AttributeTypeDescription
objAny = NoneThe underlying object whose attributes are being exposed through a dictionary-like interface.
iterkeyscallableA reference to the internal method used to iterate over the attribute names of the wrapped object.
iteritemscallableA reference to the internal method used to iterate over the attribute name and value pairs of the wrapped object.
itervaluescallableA reference to the internal method used to iterate over the attribute values of the wrapped object.
itemscallableAn alias for the method that provides an iterable of the wrapped object's attribute names and values.
keyscallableAn alias for the method that provides an iterable of the wrapped object's attribute names.
valuescallableAn alias for the method that provides an iterable of the wrapped object's attribute values.

Constructor

Signature

def DictAttribute(
obj: Any
) - > None

Parameters

NameTypeDescription
objAnyThe object to be wrapped for attribute-to-dictionary interface mapping.

Signature

def DictAttribute(
obj: Any
) - > null

Parameters

NameTypeDescription
objAnyThe target object whose attributes will be accessed via dictionary-style keys.

Methods


get()

@classmethod
def get(
key: Any,
default: Any = None
) - > Any

Attempts to retrieve a value by key, returning a default value if the attribute does not exist.

Parameters

NameTypeDescription
keyAnyThe attribute name to look up.
defaultAny = NoneThe fallback value to return if the attribute is missing from the wrapped object.

Returns

TypeDescription
AnyThe attribute value if found, otherwise the provided default value.

setdefault()

@classmethod
def setdefault(
key: Any,
default: Any = None
) - > null

Sets an attribute to a default value only if it does not already exist on the wrapped object.

Parameters

NameTypeDescription
keyAnyThe attribute name to check and potentially set.
defaultAny = NoneThe value to assign if the attribute is currently missing.

Returns

TypeDescription
nullNone