Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.014 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; 'boolean': 0.16; 'compact': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'none"': 0.16; 'quicker': 0.16; 'received:209.85.213.174': 0.16; 'received:mail- yx0-f174.google.com': 0.16; 'subject:import': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'header:In-Reply-To:1': 0.23; 'testing': 0.24; 'variable': 0.24; 'message-id:@mail.gmail.com': 0.29; 'equality': 0.30; 'nov': 0.31; 'value.': 0.32; 'to:addr:python-list': 0.32; 'done': 0.33; 'probably': 0.34; 'david': 0.34; 'none': 0.36; 'two': 0.37; 'could': 0.38; 'received:google.com': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'e.g.': 0.38; 'should': 0.39; "it's": 0.39; 'subject:: ': 0.39; 'might': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'really': 0.40; 'more': 0.60; '2011': 0.62; 'hand,': 0.76; 'beware': 0.84; 'container)': 0.84; 'riley': 0.84; '\xa0also,': 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 :content-type:content-transfer-encoding; bh=K8bPFFWKqV9q5Jj3k0/nmSbn3hzJv9DAog2/YACIuZo=; b=EPK42LjaiKDMXJp6bXMwKYxAId4HJ8tyCKeS4PJc/seC2u8uqEQ7O4/tQ0WqWro+JV HNCjdTV16OUapasRlkP/9jvbaRVG8JVfBMuTYbCWVolG8sy86Rs4BeFN7JOoIYsPpkAq LL4COkSq2BLwA1bgQZI2KM5hu6RLKkRXtn7Ww= MIME-Version: 1.0 In-Reply-To: References: <4EC2B656.7050902@sequans.com> <0601B8C7-9AEF-443A-A149-0F7D356345EF@gmail.com> Date: Wed, 16 Nov 2011 08:34:02 +1100 Subject: Re: suppressing import errors From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321392845 news.xs4all.nl 6901 [2001:888:2000:d::a6]:45157 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15742 On Wed, Nov 16, 2011 at 8:20 AM, David Riley wrote: > =A0 =A0Comparisons to singletons like None should always be done with > =A0 =A0 =A0'is' or 'is not', never the equality operators. > > =A0 =A0 =A0Also, beware of writing "if x" when you really mean "if x is n= ot None" > =A0 =A0 =A0-- e.g. when testing whether a variable or argument that defau= lts to > =A0 =A0 =A0None was set to some other value. =A0The other value might hav= e a type > =A0 =A0 =A0(such as a container) that could be false in a boolean 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". ChrisA