Testing for a list

Antun Karlovac antun at antunkarlovac.com
Mon Mar 10 20:53:48 CET 2003


I guess you're right. For this particular application, I could just always have a
list, even if it's only got one item in it.

Me being lazy.

-Antun

> -----Original Message-----
> From: Thomas Wouters [mailto:thomas at xs4all.net] 
> Sent: Monday, March 10, 2003 11:13 AM
> To: Antun Karlovac
> Cc: 'Brian Quinlan'; 'Mark McEahern'; python-list at python.org
> Subject: Re: Testing for a list
> 
> 
> 
> 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