Created
March 28, 2019 20:20
-
-
Save mmguero/362b9e9b4231f6683c1fec71c244a235 to your computer and use it in GitHub Desktop.
Different ways to do namedtuple-ish stuff with python
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
########################################################## | |
import collections | |
from collections import namedtuple | |
Robot = namedtuple('Robot', 'base, hinge1, arm_len, hinge2, wrist, hand') | |
Robot.base = 260 | |
Robot.hinge1 = 20 | |
Robot.arm_len = 120 | |
Robot.hinge2 = 150 | |
Robot.wrist = 90 | |
Robot.hand = 0 | |
# not an iterable. | |
print(Robot.hinge2) | |
########################################################## | |
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) | |
########################################################## | |
theme = lambda: None | |
theme.col_background = '#e7e7e7' | |
theme.col_header = '#707070' | |
theme.col_stroke = '#000' | |
theme.hide_tick = '#888' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Even better:
https://bitbucket.org/ericvsmith/namedlist