Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5589
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.049 |
| X-Spam-Evidence | '*H*': 0.90; '*S*': 0.00; 'else:': 0.03; 'list)': 0.09; 'written': 0.12; 'def': 0.13; 'am,': 0.14; 'wrote:': 0.14; 'executed.': 0.16; 'input': 0.18; 'tue,': 0.20; 'cc:2**0': 0.20; 'cheers,': 0.20; 'subject:list': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'clause': 0.23; 'chris': 0.27; 'pass': 0.27; 'function': 0.27; 'message-id:@mail.gmail.com': 0.28; 'hey': 0.29; 'opposed': 0.29; 'list': 0.30; 'cc:addr:python.org': 0.31; '17,': 0.31; 'joe': 0.31; 'all,': 0.31; 'test': 0.33; 'normally': 0.35; 'print': 0.35; 'quite': 0.36; 'list,': 0.36; 'else': 0.37; 'should': 0.37; 'received:209.85': 0.37; 'received:google.com': 0.38; 'used': 0.38; 'received:209': 0.39; 'would': 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'as:': 0.64; '8bit%:100': 0.67; "'you": 0.68; 'skip:\xc2 10': 0.83; 'pass:': 0.84; 'false;': 0.91; 'received:209.85.218.46': 0.91; 'received:mail- yi0-f46.google.com': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=TtqMzMZxSMQ5NIlrpRURMhnMyoepN+XKPQ2li/QxwuU=; b=ZL/0K8dv6RMbf5zvQ7gp8XpOleOWunNgb+ot/PHxaP8bRYmuKkh5I+B8FM53j5wshn c1ZS6BzUXxGSzG/KFxpLN6CQxvybvezJl81dW9n8zuSxnzR+e0YrbPvQBSfjCblfMQx6 PjxqI+kfp/PLT/2I4BBw9atQAEa00sPkb+2IQ= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=RipnRJwyl7iERXNLarg8x+nd0vFweGa3vwLUO71t/HcxkdjxKzgn41/AnacPUyCRw8 CrNbaIsyqSluygqAhmZ99aioRmB96JAiN66vja+EhFWziRYDXqG8NqE9W3YXlhxRC4ah 2OeR4gVaiRNF+Eq08NeHRy1AyXFtQERc19I+0= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> |
| References | <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> |
| Date | Tue, 17 May 2011 11:31:19 -0700 |
| X-Google-Sender-Auth | TMsBy2XJWM8DzqhDq1DpBzM9Z5g |
| Subject | Re: if statement on lenght of a list |
| From | Chris Rebert <clp2@rebertia.com> |
| To | Joe Leonardo <joe.leonardo@datalogix.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1688.1305657082.9059.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305657082 news.xs4all.nl 49047 [::ffff:82.94.164.166]:46715 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5589 |
Show key headers only | View raw
On Tue, May 17, 2011 at 11:02 AM, Joe Leonardo
<joe.leonardo@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:
> 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.
Your test should use `or` as opposed to `and`. Since you're indeed
passing in a list, the first part of your condition is False; since
you used `and`, this makes the entire condition False. Therefore, the
else clause ("YAY!") gets executed.
Also, your test is written quite strangely. One would more normally
and straightforwardly write it as:
if not isinstance(value, list) or len(value) != 19:
Cheers,
Chris
--
http://rebertia.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: if statement on lenght of a list Chris Rebert <clp2@rebertia.com> - 2011-05-17 11:31 -0700
csiph-web