Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created February 4, 2011 23:25
Show Gist options
  • Save phiggins42/812004 to your computer and use it in GitHub Desktop.
Save phiggins42/812004 to your computer and use it in GitHub Desktop.
i was confused.
#!/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