Python required variable style
Posted
by Adam Nelson
on Stack Overflow
See other posts from Stack Overflow
or by Adam Nelson
Published on 2010-05-17T20:40:32Z
Indexed on
2010/05/17
20:50 UTC
Read the original article
Hit count: 220
python
What is the best style for a Python method that requires the keyword argument 'required_arg':
def test_method(required_arg, *args, **kwargs:
def test_method(*args, **kwargs):
required_arg = kwargs.pop('required_arg')
if kwargs:
raise ValueError('Unexpected keyword arguments: %s' % kwargs)
Or something else? I want to use this for all my methods in the future so I'm kind of looking for the best practices way to deal with required keyword arguments in Python methods.
© Stack Overflow or respective owner