Checking for dlls in ctypes

Nobody nobody at nowhere.com
Sat Oct 13 07:32:14 EDT 2012


On Fri, 12 Oct 2012 12:28:17 -0400, Dave Angel wrote:

> Using bare excepts is almost never a good idea.  If it "works" you get no
> clues what went wrong.  For example, a typo in source code can trigger a
> bare exception, as can a user typing Ctrl-C.   So when you're using bare
> excepts, you have robbed the user of any way to terminate the program.

If you want to catch any error, use "except StandardError:". That covers
all errors but not things like KeyboardInterrupt (Ctrl-C) or SystemExit
(sys.exit()).

In situations such as this, where you try multiple candidates until one
succeeds, there's no reason to be any more specific than that. In any
case, Python's lack of formal interfaces makes it hard to reliably be more
specific.

However: you should bear in mind that loading the wrong DLL may just
result in an OS-level exception (e.g. segfault), which can't be caught.
It's preferable to allow the DLL to be explicitly selected e.g. in a
configuration file.




More information about the Python-list mailing list