Skip to content

Instantly share code, notes, and snippets.

@mmguero
Created March 28, 2019 20:20
Show Gist options
  • Save mmguero/362b9e9b4231f6683c1fec71c244a235 to your computer and use it in GitHub Desktop.
Save mmguero/362b9e9b4231f6683c1fec71c244a235 to your computer and use it in GitHub Desktop.
Different ways to do namedtuple-ish stuff with python
##########################################################
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'
@mmguero
Copy link
Author

mmguero commented Mar 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment