converting from perl: variable sized unpack

David Bolen db3l at fitlinxx.com
Fri Jul 20 01:21:48 EDT 2001


philh at comuno.freeserve.co.uk (phil hunt) writes:

> On Wed, 18 Jul 2001 23:48:01 +0200, Alex Martelli <aleaxit at yahoo.com> wrote:
> >"phil hunt" <philh at comuno.freeserve.co.uk> wrote in message
> >news:slrn9lavp6.v3.philh at comuno.freeserve.co.uk...
> >    ...
> > (...)
> >> No, because on the odd occasions that you want an exception you can
> >> always throw one manually.
> >
> >And viceversa, if the odd occasions are those in which you
> >want to SUPPRESS the exception, you can easily try/except it.
> 
> On the contrary, i want to suppress the exception >90% of the
> time.

and earlier, philh at comuno.freeserve.co.uk (phil hunt) wrote:

> Here, I'm assuming that usually you don't want one -- perhaps this
> is jsut my idiosyncratic programming style and most people vare different
> here. Comments?

I think it does seem like you're going to end up fighting Python quite
a bit with this goal.  Exceptions really are integral to Python (much
more so than many other languages that also support the notion) and
working hard to avoid them as much as you suggest may be just too much
swimming against the tide.

And this is true outside the core objects/libraries as well.  A really
good example is the win32all package, which wraps the majority of the
win32 API.  Any error code back from the API is translated into an
exception.  So that's an example of a non-exception API conforming to
exceptions from within the Python environment.

I don't want to pre-suppose how much experience you have working with
them to this point, but I'm guessing that if you become more
comfortable with programming in the presence of exceptions (e.g.,
accept that it can happen in far more than 10% of the code you write),
that you'll find it neither as intrusive as you suggest in this
thread, nor problematic.  Of course you can always wrap exceptions up
in your own functions as has been shown here, and can always choose at
what level you want to catch exceptions.  Exception handling at
logical points in an application (e.g., not really each and every
statement) can go a long way to amortizing the overhead of dealing
with them.

Personally, I also find the exception approach very valuable to quick
'n dirty scripts.  It gives you extra confidence to whip up those
really dirty one-shot tools, knowing that if something fails the
exception will bubble up a trackback and just stop things.  I'm always
a bit more leary of that rapidly-built more than single liner, but
less than large application, Perl script in terms of automatic
coersions, empty results to bad references and so on, for example.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list