Created
February 4, 2011 23:25
-
-
Save phiggins42/812004 to your computer and use it in GitHub Desktop.
i was confused.
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
test.py | |
""" | |
class Foo(object): | |
def kwargdefaults(self, **kwargs): | |
return { | |
"a": kwargs.get("foo", "bar") | |
} | |
def howtoreturnkwargs(self): | |
return { "a":1, "b":2, "c":{ "a":3 }, "d":False } | |
def testy(self, **kwargs): | |
print "called." | |
for arg in kwargs: | |
print arg, "===", kwargs[arg] | |
def __init__(self): | |
self.testy() | |
self.testy(a=1, b=2, c={ 'a':3 }, d=False) | |
# if you skip the **, it's just passing one arg as a literal unnamed. which is an error. | |
self.testy(**self.howtoreturnkwargs()) | |
# for fun | |
self.testy(**self.kwargdefaults()); | |
self.testy(**self.kwargdefaults(foo="bam")); | |
if __name__ == "__main__": | |
foo = Foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment