Function Overloading Without Typechecking
Fernando Pérez
fperez528 at yahoo.com
Mon Jan 14 07:10:12 EST 2002
Emile van Sebille wrote:
> I look to make a function that will do the right thing for the
> allowable args and then use it. For your example, something
> like:
>
>>>> def tolist(arg):
> return filter(None, [a.strip() for a in list(arg)])
>
>>>> tolist('a b c')
> ['a', 'b', 'c']
>>>> tolist(['a','b','c'])
> ['a', 'b', 'c']
>
But your version does:
In [21]: tolist('a bcd e')
Out[21]=
['a', 'b', 'c', 'd', 'e']
while I think he'd want:
In [22]: 'a bcd e'.split()
Out[22]=
['a', 'bcd', 'e']
I'm *very* interested in an elegant, 'pythonic' solution to this, as I tend
to do a lot of what the original poster does and would love to learn of a
better, more robust way to do it.
Thanks,
f.
More information about the Python-list
mailing list