Created
September 24, 2024 23:03
-
-
Save wassname/33ef989ab06325daeeef68be1d638a2c to your computer and use it in GitHub Desktop.
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 setattrattr(cfg, k, v): | |
""" | |
Sets an attr even it's like o.a.b | |
Usage: | |
setattrattr(obj, 'loss.alpha', 0.1) | |
https://gist.github.com/wassname/33ef989ab06325daeeef68be1d638a2c/edit | |
""" | |
if '.' in k: | |
k, k2 = k.split('.') | |
parent = getattr(cfg, k) | |
return setattrattr(parent, k2, v) | |
else: | |
return setattr(cfg, k, v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment