Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '"if': 0.04; 'defaults': 0.07; 'compares': 0.09; 'am,': 0.12; '16,': 0.15; 'argument': 0.15; 'cc:addr:python-list': 0.15; 'boolean': 0.16; 'compact': 0.16; 'none"': 0.16; 'quicker': 0.16; 'subject:import': 0.16; 'received:74.125.82.44': 0.17; 'received:mail-ww0-f44.google.com': 0.17; 'wed,': 0.17; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.23; 'testing': 0.24; 'variable': 0.24; 'cc:2**0': 0.25; 'cc:addr:python.org': 0.29; 'message- id:@mail.gmail.com': 0.29; 'equality': 0.30; 'chris': 0.30; 'nov': 0.31; 'value.': 0.32; 'done': 0.33; 'probably': 0.34; 'david': 0.34; 'none': 0.36; 'received:74.125.82': 0.37; 'two': 0.37; 'could': 0.38; 'received:google.com': 0.38; 'some': 0.38; 'e.g.': 0.38; 'received:74.125': 0.39; 'should': 0.39; "it's": 0.39; 'subject:: ': 0.39; 'might': 0.39; 'really': 0.40; 'more': 0.60; '2011': 0.62; 'skip:\xc2 10': 0.73; 'hand,': 0.76; 'beware': 0.84; 'container)': 0.84; 'idiomatic': 0.84; 'riley': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=/DtcgKW7+FTbAAJzymb3stZyIfKkyOBZ5sNPj2MRhjY=; b=sXz23WNVUcRFL++v2eo4zleivPF5Ajr8gG5jv4Qe1d3orLsfeUPdp17pLFzAxsEjBm RqlMBIZUJRiFx/+WF157dpL/Ob5zcU6+OCxTx2sqh2r/k8OK9yDiC00a1+HzjfjAIDLq PPpM8KTcFtflLrnTRdjFb9zYWs8CExJVy8mo8= MIME-Version: 1.0 In-Reply-To: References: <4EC2B656.7050902@sequans.com> <0601B8C7-9AEF-443A-A149-0F7D356345EF@gmail.com> Date: Tue, 15 Nov 2011 21:42:22 +0000 Subject: Re: suppressing import errors From: Arnaud Delobelle To: Chris Angelico Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321393344 news.xs4all.nl 6951 [2001:888:2000:d::a6]:58930 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15743 On 15 November 2011 21:34, Chris Angelico wrote: > On Wed, Nov 16, 2011 at 8:20 AM, David Riley wrote= : >> =C2=A0 =C2=A0 =C2=A0Comparisons to singletons like None should always be= done with >> =C2=A0 =C2=A0 =C2=A0'is' or 'is not', never the equality operators. >> >> =C2=A0 =C2=A0 =C2=A0Also, beware of writing "if x" when you really mean = "if x is not None" >> =C2=A0 =C2=A0 =C2=A0-- e.g. when testing whether a variable or argument = that defaults to >> =C2=A0 =C2=A0 =C2=A0None was set to some other value. =C2=A0The other va= lue might have a type >> =C2=A0 =C2=A0 =C2=A0(such as a container) that could be false in a boole= an context! > > It's probably quicker to execute "if x is None" than "if x" > (presumably the former just compares the two pointers). On the other > hand, it's more compact to leave off the "is None". And on the > gripping hand, neither "quicker to execute" nor "more compact" equates > to "more Pythonic". It's idiomatic to write "x is None" when you want to know whether x is None= . --=20 Arnaud