Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15734

Re: suppressing import errors

Subject Re: suppressing import errors
From David Riley <fraveydank@gmail.com>
Date 2011-11-15 14:39 -0500
References <CAC82khmG+zH3Cd5pRfou+0FED18MHfizLzJL4EM+V+Pw+q17+w@mail.gmail.com> <CALvWhxvc=Ng28YeiL0Onv9YCixfQtOqgLENWJqYgoRSYvo_juA@mail.gmail.com> <CAC82khn3WBjXY7podVq6RX0d0j38w1vbtN3fNOCSGLcu2X_jOw@mail.gmail.com> <D97140E4-9B09-4EAE-BB92-0F038FCDBA5A@gmail.com> <4EC2B656.7050902@sequans.com>
Newsgroups comp.lang.python
Message-ID <mailman.2744.1321385952.27778.python-list@python.org> (permalink)

Show all headers | View raw


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 <module> is None:" (or, of course, "is not None").

- Dave

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: suppressing import errors David Riley <fraveydank@gmail.com> - 2011-11-15 14:39 -0500

csiph-web