-
Notifications
You must be signed in to change notification settings - Fork 119
SUGGESTION: string version of sequence of attributes #298
Copy link
Copy link
Open
Description
The following piece of code could be added in the source code, which allows using myboxobj("a.b.c.d") instead of myboxobj.a.b.c.d. This simplifies some dynamic coding.
#!/usr/bin/env python3
from box import Box
# ---------------------- #
# -- BETTER BOX CLASS -- #
# ---------------------- #
###
# We make the class Box callable to allow the use of virtual
# pointed paths.
###
class BoxPlus(Box):
###
# prototype::
# content : a pointed path similar to a sequence of
# attribute request.
#
# :return: the expected value.
###
def __call__(
self,
str_attrs
):
val = self
for n in str_attrs.split('.'):
val = getattr(val, n)
return valReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels