Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!amsnews11.chello.com!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"if': 0.04; 'context': 0.04; 'warnings': 0.05; 'defaults': 0.07; 'python': 0.08; 'comparisons': 0.09; 'not?': 0.09; 'am,': 0.12; '16,': 0.15; 'argument': 0.15; 'cc:addr:python-list': 0.15; '"none"': 0.16; 'boolean': 0.16; 'general.': 0.16; 'namespace.': 0.16; 'none"': 0.16; 'obviously,': 0.16; 'subject:import': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; "doesn't": 0.23; 'pep': 0.23; "shouldn't": 0.23; 'header:In-Reply-To:1': 0.23; 'testing': 0.24; 'variable': 0.24; 'cc:2**0': 0.25; 'received:209.85.220': 0.27; 'not.': 0.27; 'bit': 0.28; 'true,': 0.28; 'cc:addr:python.org': 0.29; 'module': 0.30; 'equality': 0.30; 'chris': 0.30; 'nov': 0.31; 'pm,': 0.31; 'value.': 0.32; 'does': 0.32; "can't": 0.32; "i've": 0.33; 'instead': 0.33; 'there': 0.33; 'done': 0.33; 'apply': 0.33; 'message- id:@gmail.com': 0.34; 'probably': 0.34; 'david': 0.34; 'however,': 0.34; 'object': 0.35; 'none': 0.36; 'gotten': 0.36; 'could': 0.38; 'received:google.com': 0.38; 'some': 0.38; 'perhaps': 0.38; 'received:209.85': 0.38; 'received:192': 0.38; 'e.g.': 0.38; 'should': 0.39; "it's": 0.39; 'why': 0.39; 'subject:: ': 0.39; 'might': 0.39; 'received:209': 0.40; 'really': 0.40; '2011': 0.62; 'header:Message-Id:1': 0.62; 'evaluate': 0.71; 'beware': 0.84; 'container)': 0.84; 'received:192.168.8': 0.84; 'riley': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=GfdwCYUplMnln3WY6zvlyA4vukR5A2rwMiHLnIgRzt8=; b=w21gyeugcE0eWZGXijcAoNivAVAV+5zOA4Buero8DucF7LUhTwzvc/LkApJh8kPz6f If6C4oBWTV6x5sTOhxTj5aUAjIsb5yESipzXSCwygm7ag2QNHoDzOnQ1WsvD3vUFyX08 K/8jEktivHPEUro6QO/tUKLrq0m/uzhSVV03k= Subject: Re: suppressing import errors Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=iso-8859-1 From: David Riley In-Reply-To: Date: Tue, 15 Nov 2011 16:20:33 -0500 Content-Transfer-Encoding: quoted-printable References: <4EC2B656.7050902@sequans.com> <0601B8C7-9AEF-443A-A149-0F7D356345EF@gmail.com> To: Chris Angelico X-Mailer: Apple Mail (2.1251.1) 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321392039 news.xs4all.nl 6922 [2001:888:2000:d::a6]:57139 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15741 On Nov 15, 2011, at 3:01 PM, Chris Angelico wrote: > On Wed, Nov 16, 2011 at 6:39 AM, David Riley = wrote: >> True, and that does avoid polluting namespace. However, you = shouldn't be testing for None as a bool; you should instead do an "if = is None:" (or, of course, "is not None"). >=20 > Why not? Is there some other way for the module object to evaluate as = false? Well, probably not. It was my understanding that "None" evaluating to a = Boolean false was not necessarily guaranteed; I've even gotten some = warnings from Python to that effect, though I can't recall the context = in which that happened. In any case, PEP 8 states: Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. Also, beware of writing "if x" when you really mean "if x is not = None" -- e.g. when testing whether a variable or argument that defaults = to None was set to some other value. The other value might have a = type (such as a container) that could be false in a boolean context! Obviously, that last bit doesn't apply to modules; they're not going to = evaluate as False in general. I just bristle when I see people writing = "if x" when they really mean "if x is not None", perhaps because it's = not The Right Way(tm)? It mostly comes down to aesthetics, I guess. = Write what you really mean. - Dave