As you can see, keyword arguments with default values ββcan go a long way.
I also declare that, in my opinion, it is against the spirit of Python to worry about which types are passed to methods. In Python, I find it more acceptable to use duck typing - asking what the object can do, rather than what it is.
That way, if your method can take a string or tuple, you can do something like this:
def print_names(names): """Takes a space-delimited string or an iterable""" try: for name in names.split():
Then you can do one of the following:
print_names("Ryan Billy") print_names(("Ryan", "Billy"))
Although such an API sometimes indicates a design problem.
Ryan Ginstrom Apr 09 '09 at 9:48 2009-04-09 09:48
source share