How do I test if an object is a sequence?

Jp Calderone exarkun at intarweb.us
Mon Dec 22 09:33:04 EST 2003


On Mon, Dec 22, 2003 at 03:11:55PM +0100, Max M wrote:
> Is there a common idiom for testing if an object is a sequence?
> 

  Define sequence more thoroughly.  I was with your description, up to the
point where you said you didn't think strings qualified.  Now I'm not sure
what you're looking for.

  For example, do arrays count (array.array)?  I guess unicode is out, if
strings are, but what about other kinds of strings (UserString or subclasses
of StringType)?

  Or maybe a better question would be this - *why* do you want a function
that returns True when passed a list or a tuple or one of these mysterious
"non-standard objects", but False when passed a string, an integer, or
something else of that variety?

  Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20031222/0f3312c4/attachment.sig>


More information about the Python-list mailing list