Last active
September 16, 2022 12:29
-
-
Save yusuke0519/3e97b1dbbdb530a03d0bc6ca7feaa4a7 to your computer and use it in GitHub Desktop.
再帰的なsetattr(nameが"."を含む場合のsetattr)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recursive_setattr(obj, name, value): | |
if '.' in name: | |
parent, child = name.split('.')[0], '.'.join(name.split('.')[1:]) | |
recursive_setattr(getattr(obj, parent), child, value) | |
else: | |
setattr(obj, name, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment