Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"if': 0.04; 'assign': 0.04; 'symbols': 0.07; 'bool': 0.09; "module's": 0.09; 'cc:addr :python-list': 0.15; 'namespace,': 0.16; 'namespace.': 0.16; 'subject:import': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; 'avoiding': 0.23; "shouldn't": 0.23; 'header:In-Reply-To:1': 0.23; 'testing': 0.24; 'import': 0.28; 'true,': 0.28; 'cc:addr:python.org': 0.29; 'cc:addr:gmail.com': 0.30; 'module': 0.30; 'nov': 0.31; 'pm,': 0.31; 'does': 0.32; 'instead': 0.33; 'there': 0.33; 'message-id:@gmail.com': 0.34; 'received:209.85.212': 0.34; 'test': 0.34; 'however,': 0.34; 'cc:2**1': 0.36; 'none': 0.36; 'using': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'received:192': 0.38; 'should': 0.39; 'subject:: ': 0.39; 'received:209': 0.40; 'your': 0.61; 'header:Message-Id:1': 0.62; 'received:192.168.8': 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=u8ZNfB9lOz/gUcNSS+hBlOIN4EGX2ZOr0pHOtNF7Juk=; b=vf1gQGb2YQvqY6tyvbSLX6RvX5/P24TTlpzQ1QLEvitPO4+dlfgNhqD1GrIfZWtX67 m/eKrnvT0LcdC6tAa4neFaa9ytG6yL/78jxQxArs8QG1Q7355MYDahRdNH8yzjsDDh2j d/JhCAGg1/VPm5zN+1z4cemzm5ESGjGGpSgss= 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: <4EC2B656.7050902@sequans.com> Date: Tue, 15 Nov 2011 14:39:01 -0500 Content-Transfer-Encoding: quoted-printable References: <4EC2B656.7050902@sequans.com> To: Jean-Michel Pichavant 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: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321385952 news.xs4all.nl 6967 [2001:888:2000:d::a6]:41291 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15734 On Nov 15, 2011, at 1:58 PM, Jean-Michel Pichavant wrote: > PS : @Dave there is a way to avoiding adding symbols to your global = namespace, assign None to the module's name on import errors. Then = before using it, just test the module bool value : if serial: = serial.whateverMethod() 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"). - Dave