Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21626
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'test,': 0.04; 'received:verizon.net': 0.07; 'terry': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'read.': 0.10; "'not": 0.16; 'agree.': 0.16; 'indexerror:': 0.16; 'reedy': 0.16; 'subject:Poll': 0.16; 'subject:question': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'say,': 0.19; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'index': 0.24; 'suspect': 0.24; 'function': 0.27; 'not.': 0.28; 'pass': 0.29; 'pm,': 0.29; 'does': 0.32; 'break': 0.32; 'list': 0.32; 'header :User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.34; 'loop': 0.34; 'try:': 0.34; '(not': 0.35; 'to:addr:python-list': 0.35; 'list:': 0.35; 'received:org': 0.36; 'but': 0.37; 'except': 0.39; 'subject: (': 0.40; 'to:addr:python.org': 0.40; 'march': 0.61; 'matter': 0.62; 'making': 0.64; "'if": 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Style question (Poll) |
| Date | Wed, 14 Mar 2012 17:16:05 -0400 |
| References | <CANm61jcTZNVJAbkj2ZGJ+X1-mUZOoXsR90VstC4rb8UOo1x8Ug@mail.gmail.com> <CAJ6cK1b4Kop1uvEKLXUV3qBZkAajf+g-+i3pTksUVHxazy5EFg@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-74-109-121-73.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| In-Reply-To | <CAJ6cK1b4Kop1uvEKLXUV3qBZkAajf+g-+i3pTksUVHxazy5EFg@mail.gmail.com> |
| 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.653.1331759783.3037.python-list@python.org> (permalink) |
| Lines | 64 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1331759783 news.xs4all.nl 6928 [2001:888:2000:d::a6]:47159 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21626 |
Show key headers only | View raw
On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > On 14 March 2012 20:37, Croepha<croepha@gmail.com> wrote: >> Which is preferred: >> >> for value in list: >> if not value is another_value: >> value.do_something() >> break Do you really mean 'is' or '=='? If you mean x is not y, write it that way. 'not x is y' can be misread and misunderstood, depending on whether the 'is' is true or not. >>> not 1 is 1 False >>> not (1 is 1) False >>> (not 1) is 1 False Does not matter how read. >>> not (1 is 0) True >>> (not 1) is 0 False >>> not 1 is 0 True Does matter how read. >> if list and not list[0] is another_value: >> list[0].do_something() Or try: value = mylist[0] if value is not another_value: value.dosomething except IndexError: pass I would not do this in this case of index 0, but if the index were a complicated expression or expensive function call, making 'if list' an inadequate test, I might. > Hard to say, since they don't do the same thing :) > > I suspect you meant: > > for value in list: > if not value is another_value: > value.do_something() > break > > I always feel uncomfortable with this because it's misleading: a loop > that never loops. I agree. Please do not do this in public ;-). -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Style question (Poll) Terry Reedy <tjreedy@udel.edu> - 2012-03-14 17:16 -0400 Re: Style question (Poll) Jon Clements <joncle@googlemail.com> - 2012-03-15 10:13 -0700 Re: Style question (Poll) Jon Clements <joncle@googlemail.com> - 2012-03-15 10:13 -0700
csiph-web