I am implementing a function with three keywords. The default value for each keyword is None
, but I need to force the user to pass at least one keyword. The reason why I want to use keywords is that the keyword names a, b
and c
are descriptive, and will help the user to figure out what does he need to pass to method
. How do I achieve my task?
def method(a=None, b=None, c=None):
if a!=None:
func_a(a)
elif b!=None:
func_b(b)
elif c!=None:
func_c(c)
else:
raise MyError('Don\'t be silly, user - please!')
In the above example, assume of course that a, b
and c
have different attributes. The obvious solution would be:
def method(x):
if is_instance(x, A):
func_a(x)
elif is_instance(x, B):
func_b(x)
[...]
But the problem is that as I said I want to use the keyword names a, b
and c
to help the user understand what he does need to pass to method
!
Is there a more pythonic way to achieve the result?