Created
August 28, 2011 11:20
-
-
Save zeffii/1176555 to your computer and use it in GitHub Desktop.
alternative to namedtuple is auto_class
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
# as suggested and clarified by Campbell Barton, in the first response to this post. | |
# Here's an example of a helper function to do new classes that work like named tuples | |
# ---- | |
# 1 liner for making new named tuple like classes | |
def auto_class(name, slots): return type(name, (object, ), {"__slots__": slots}) | |
mytype = auto_class("TrickyClass", ("blah", "whee", "whoo")) | |
t = mytype() | |
t.whoo = 10 | |
print(t.whoo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment