Popular recipes tagged "argument"http://code.activestate.com/recipes/tags/argument/2011-11-03T18:31:52-07:00ActiveState Code RecipesEmulate Keyword-Only Arguments in Python 2 (Python) 2011-11-03T18:31:52-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577940-emulate-keyword-only-arguments-in-python-2/ <p style="color: grey"> Python recipe 577940 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/argument/">argument</a>, <a href="/recipes/tags/keyword_only/">keyword_only</a>, <a href="/recipes/tags/kwonly/">kwonly</a>, <a href="/recipes/tags/parameter/">parameter</a>). </p> <p>Python 3 introduced a useful feature: keyword-only arguments. In order to get the same effect in Python 2, you must use **kwargs in your parameter list. Then, at the beginning of your function body you must manually extract what would be the keyword-only arguments once you upgrade to 3.</p> <p>This recipe helps reduce the boilerplate to a single function call. You still don't get those parameters in your "def" clause (where they are more obvious), but at least it reduces the clutter.</p>