Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
trollynamedtuple.py
import sys
def trollynamedtuple_init(self, *args):
for prop, arg in zip([i for i in dir(self) if not i.startswith('__')], args):
setattr(self, prop, arg)
def trollynamedtuple(typename, field_names):
tempclass = type(typename, (object,), {k: None for k in field_names.split()})
tempclass.__init__ = trollynamedtuple_init
parent_frame = sys._getframe(1)
parent_frame.f_locals[typename] = tempclass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment