Refactor exporter into Export class

This commit is contained in:
JonnyWong16 2020-09-20 20:34:31 -07:00
parent ca06154805
commit 7eedb14834
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
3 changed files with 1285 additions and 1081 deletions

View file

@ -1267,15 +1267,11 @@ def flatten_tree(obj, key=''):
# https://stackoverflow.com/a/14692747
def get_by_path(root, items):
"""Access a nested object in root by item sequence."""
if isinstance(items, str):
items = items.split('.')
return reduce(operator.getitem, items, root)
def set_by_path(root, items, value):
"""Set a value in a nested object in root by item sequence."""
if isinstance(items, str):
items = items.split('.')
get_by_path(root, items[:-1])[items[-1]] = value