suppressing import errors

David Riley fraveydank at gmail.com
Tue Nov 15 14:39:01 EST 2011


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




More information about the Python-list mailing list