Hello BangPypers,

Python 3 has this nifty feature of including the * in the argument list to indicate the end of positional arguments and the beginning of keyword-only arguments.

For example:
def my_func(a, b, *, kw1=None, kw2=None): pass

In Python 2 you could achieve the same goal of enforcing keyword-only arguments using a technique like below example function:

def my_func(a, b, **kwargs):
    kw1 = kwargs.pop('kw1', None)
    kw2 = kwargs.pop('kw2', None)

Would you consider this technique of enforcing keyword-only argument in Python 2 idiomatic?

I understand that it could be a matter of personal taste. But I'm curious to know what other Python programmers think about it.

-
Sudheer Satyanarayana


_______________________________________________
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers

Reply via email to