Created
July 21, 2012 19:19
-
-
Save mattrobenolt/3156887 to your computer and use it in GitHub Desktop.
Python unpacking with **
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
class foo(object): | |
a = 'b!' | |
b = 'b!' | |
def keys(self): | |
return ['a', 'b'] | |
def __getitem__(self, item): | |
return getattr(self, item) | |
print dict(**foo()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The minimum needed to "unpack" an object is a
keys
and__getitem__
method.