18 lines
454 B
Python
18 lines
454 B
Python
from typing import Any
|
|
|
|
|
|
def set_nested_attr(target: Any, key: str, value: Any):
|
|
parts = key.split(".")
|
|
for part in parts[:-1]:
|
|
target = getattr(target, part)
|
|
setattr(target, parts[-1], value)
|
|
|
|
|
|
def set_dict_nested_value(target: dict, key: str, value: Any):
|
|
parts = key.split(".")
|
|
for part in parts[:-1]:
|
|
if part not in target:
|
|
target[part] = {}
|
|
target = target[part]
|
|
target[parts[-1]] = value
|