-
-
Save jeetsukumaran/d1010a04e518e848581c9b6857a27b2f to your computer and use it in GitHub Desktop.
Simple Bare-Bones Data-as-Attributes Classes
This file contains hidden or 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
# "heavy" approach (can be useful if you want to derive | |
# and add simple behavior, e.g. validation etc.) | |
class Attributes: | |
def __init__(self, **kwargs): | |
# Alternatively: | |
# self.__dict__.update(kwargs) | |
for k, v in kwargs.items(): | |
setattr(self, k, v) | |
# or otherwise: | |
d = lambda: None | |
d.foo = "bar" | |
d.moo = "baaaaaaaaa" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment