How do I distinguish a string from a sequence?

Emile van Sebille emile at fenx.com
Fri Sep 28 10:05:16 EDT 2001


"Paul Moore" <paul.moore at atosorigin.com> wrote in message
news:v3v8rtsdmp5ij8bqq7pfndnf6rihm3bujd at 4ax.com...
> Yes, I know, a string is a sequence...
>
> I'm thinking of writing a function which can take either a string, or a
sequence
> of strings, as an argument.

As long as you're still thinking about it, you could make the interface
non-ambiguous ala
def foo(cmdStr=None, cmdList=None):

> A simplified example would be treating a single
> string as a 1-tuple - something like
>
>    def foo(args):
>       if # args is a string:
>          args = (args,)
>       for arg in args:
>          print arg
>
> But I'm not sure how best to distinguish a string from a sequence

Maybe it's easier then to distinguish a sequence from a string?  ;-)

isinstance(args, .types.ListType)

HTH,

--

Emile van Sebille
emile at fenx.com






More information about the Python-list mailing list