Skip to content

Instantly share code, notes, and snippets.

@suzukimilanpaak
Created May 23, 2020 18:20
Show Gist options
  • Save suzukimilanpaak/ad529ae4b37e0313e573ef3f47f289a4 to your computer and use it in GitHub Desktop.
Save suzukimilanpaak/ad529ae4b37e0313e573ef3f47f289a4 to your computer and use it in GitHub Desktop.
Ruby's Openstruct alternative in Python
class OpenStruct:
def __init__(self, **dic):
self.__dict__.update(dic)
def __getattr__(self, i):
if i in self.__dict__:
return self.__dict__[i]
else:
None
def __setattr__(self,i,v):
if i in self.__dict__:
self.__dict__[i] = v
else:
self.__dict__.update({i:v})
return v # i like cascates :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment