if statement on lenght of a list

Joe Leonardo joe.leonardo at datalogix.com
Tue May 17 14:02:03 EDT 2011


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:
        print 'You must pass a list that contains 19 fields.'
    else:
        print 'YAY!'

If I pass:
breakLine([])

I get:
YAY!

I expect:
You must pass a list that contains 19 fields.

If I print len(value) I get: 0

What is going on here?

Thanks!




[cid:image001.png at 01CC148A.3C0C1950]

Joe Leonardo | Business Intelligence Analyst | DataLogix<http://www.datalogix.com>
303.327.1730 d | 415.812.5244 c | joe.leonardo at datalogix.com<mailto:joe.leonardo at datalogix.com>

Better Marketing through Data(tm)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110517/5baa4d1b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 3465 bytes
Desc: image001.png
URL: <http://mail.python.org/pipermail/python-list/attachments/20110517/5baa4d1b/attachment.png>


More information about the Python-list mailing list