if statement on lenght of a list

Jerry Hill malaclypse2 at gmail.com
Tue May 17 14:28:02 EDT 2011


On Tue, May 17, 2011 at 2:02 PM, Joe Leonardo <joe.leonardo at datalogix.com>wrote:

> Hey all,
>
>
>
> Totally baffled by this…maybe I need a nap. Writing a small function to
> reject input that is not a list of 19 fields.
>
>
>
> def breakLine(value):
>
>     if value.__class__() != [] and value.__len__() != 19:
>
>
This should use an "or" test, not "and".  And is probably better written as:
    if not isinstance(value, list) or len(value) != 19:

That would allow for subclasses of list, assuming that would be okay.

-- 
Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110517/57eb5671/attachment.html>


More information about the Python-list mailing list