Hello,
what is an appropriate solution to limit the number of optional, positional arguments for a function or method? E.g. I'd like to have a function that takes either two or three positional arguments (but not more). I cannot use an optional keyword argument (because the function needs to accept an unlimited number of arbitrarily named keyword arguments). What I've come up with so far is something like this:
def foo(x, y, *args, **kwargs):
if len(args) == 1:
# do something
elif len(args) > 1:
raise TypeError, "foo expected at most 3 arguments, got %d" % (len(args) + 2)
else
# do something else
Does this reasonable or is there a better way?