Skip to content

Instantly share code, notes, and snippets.

@mattrobenolt
Created July 21, 2012 19:19
Show Gist options
  • Save mattrobenolt/3156887 to your computer and use it in GitHub Desktop.
Save mattrobenolt/3156887 to your computer and use it in GitHub Desktop.
Python unpacking with **
class foo(object):
a = 'b!'
b = 'b!'
def keys(self):
return ['a', 'b']
def __getitem__(self, item):
return getattr(self, item)
print dict(**foo())
@mattrobenolt
Copy link
Author

The minimum needed to "unpack" an object is a keys and __getitem__ method.

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