Created
December 22, 2015 16:23
-
-
Save ksindi/a224841ee169f8d5c1dc to your computer and use it in GitHub Desktop.
access namedstuples as dictionary
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
# from http://pythondoeswhat.blogspot.com/2011/09/namedtupledict.html | |
def namedtupledict(*a, **kw): | |
namedtuple = collections.namedtuple(*a, **kw) | |
def getitem(self, key): | |
if type(key) == str: | |
return getattr(self, key) | |
return tuple.__getitem__(self, key) | |
namedtuple.__getitem__ = getitem | |
return namedtuple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment