Created
February 13, 2013 18:33
-
-
Save notmyname/4946922 to your computer and use it in GitHub Desktop.
how 2 python?
This file contains 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
def foo(x, y=None, *a, **kw): | |
print '%r, %r, %r, %r' % (x, y, a, kw) | |
foo(1) | |
foo(1, 2) | |
foo(1, 2, 3, 4, 5, bar=6) | |
foo(1, 2, y=3) # want: 1, 3, (2,), {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In python, 'def foo(1, y=2, 3, 4, bar=5)' is not allowed. So if you need the key 'y' especially, could use like this:
def foo(x, _a, *_kw):
...
y = kw.pop('y', 'default value')
...
I found this is old issue 3 months ago. Do you found your best answer?