MagicAttr (current version 0.1.6) provides an enhanced `getattr` and `setattr` functionality for Python, capable of navigating and modifying attributes within deeply nested objects, lists, and dictionaries. It stands out by retaining the original cause of failure instead of exclusively raising an `AttributeError`, offering more granular error information. The library sees infrequent but active maintenance, with the latest release in January 2022.
pip install magicattrVerified import paths — ran on the pinned version, not inferred.
Demonstrates getting, setting, and deleting nested attributes using string paths, including auto-creation of intermediate dictionary structures.
Ensure attribute paths are simple dot-separated or bracket-indexed strings. Perform complex logic outside the `magicattr` call.
Inspect the return value carefully for `None` or specific exceptions like `KeyError` or `IndexError` when an attribute might not exist, rather than solely catching `AttributeError`.
Explicitly initialize intermediate objects with the desired types before using `magicattr.set()` if `dict` or `list` are not appropriate defaults.
No dependency data recorded yet.