Testing for a list

Thomas Wouters thomas at xs4all.net
Mon Mar 10 14:12:42 EST 2003


On Mon, Mar 10, 2003 at 11:04:16AM -0800, Antun Karlovac wrote:

> That's exactly what I needed.

No, it really isn't :)

> Why were people ignoring my question? What was wrong about it?

What is a list ? Is a subclass of a list also a list ? What about a Python
object that pretends to be a list ? Why do you need to check whether
something is a list anyway ? If you're doing some kind of type-checking,
it's usually better not to; instead, have your function blow up when trying
to (say) index the passed-in would-be list, informing the programmer than
one of their functions called your function with the wrong type of argument.

If you really really really want to test for list-ness, don't; instead, use
the recipe posted earlier that tests whether the object *acts* like a list.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!





More information about the Python-list mailing list