sending string or list to a function
Farshid Lashkari
no at spam.com
Mon Dec 4 19:32:28 EST 2006
manstey wrote:
> Is there a neat way to write a function that can receive either a
> string or a list of strings, and then if it receives a string it
> manipulates that, otherwise it manipulates each string in the list?
The following code shows one way you can accomplish this. I don't
consider it bad programming style to allow your functions to accept
multiple data types.
def MyFunction(val):
if isinstance(val,basestring):
val = [val]
for s in val:
#Process string
-Farshid
More information about the Python-list
mailing list