Skip to content

Instantly share code, notes, and snippets.

@jeetsukumaran
Created January 3, 2022 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeetsukumaran/d1010a04e518e848581c9b6857a27b2f to your computer and use it in GitHub Desktop.
Save jeetsukumaran/d1010a04e518e848581c9b6857a27b2f to your computer and use it in GitHub Desktop.
Simple Bare-Bones Data-as-Attributes Classes
# "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