How do I distinguish a string from a sequence?

Paul Moore gustav at morpheus.demon.co.uk
Fri Sep 28 15:42:18 EDT 2001


On Fri, 28 Sep 2001 07:05:16 -0700, "Emile van Sebille" <emile at fenx.com> wrote:
>As long as you're still thinking about it, you could make the interface
>non-ambiguous ala def foo(cmdStr=None, cmdList=None)

That's possible, but I'm not sure I like the interface like that...

>> 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)

That misses more than the other way around. There's tuples, as well as general
iterators.

Thanks for the comments,
Paul



More information about the Python-list mailing list