[lug] Python: Unable to catch subprocess error

Rob Nagler nagler at bivio.biz
Sat Mar 10 06:47:49 MST 2018


On Fri, Mar 9, 2018 at 8:12 PM, Jed S. Baer wrote:

> My understanding is that "except", by itself, is a catch-all. This would
> seem to be good practice in an error handler. It catches anything not
> explicitly handled.
>

It's just bad practice afaict. Here's some discussion:

https://stackoverflow.com/a/4990739


> Oh, that's just my being lazy, as taught by languages that do automatic
> casting. In my Pythonic endeavours to this point, haven't had to think
> about it. But thanks for the push to read up on Python string formatting.


Python is inconsistent in that way, which is why I pointed it out. If you
are doing anything serious, you'll want a wrapped print, e.g.

from __future__ import print_function

def debug_print(fmt, *args, **kwargs):
    print(fmt.format(*args, **kwargs))

Note that you'll want to "future proof" your Python. The print "statement"
was replaced by a print function in Python 3. Therefore, you'll want to
import the print_function in Python 2 from "__future__", which is a magic
module that makes "print x" invalid and "print(x)" valid.

Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20180310/a633a0ce/attachment.html>


More information about the LUG mailing list