Skip to content

Instantly share code, notes, and snippets.

@wassname
Created September 24, 2024 23:03
Show Gist options
  • Save wassname/33ef989ab06325daeeef68be1d638a2c to your computer and use it in GitHub Desktop.
Save wassname/33ef989ab06325daeeef68be1d638a2c to your computer and use it in GitHub Desktop.
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