buggy python interpretter or am I missing something here?

me noone at all.net
Mon Jan 27 02:17:43 EST 2014


On Mon, 27 Jan 2014 00:47:13 -0600, Zachary Ware wrote:

> You've missed the point here.  sys.exit() *does* raise an exception:
> SystemExit, a subclass of BaseException.  In fact, you can implement
> sys.exit in pure Python like so:
> 
> def exit(status):
>     raise SystemExit(status)
> 
> Your bare 'except:' catches that SystemExit along with any other
> possible exception; the bare 'raise' in the except clause just re-raises
> the same SystemExit, which then does what you meant for it to do in the
> first place.

Well that does change things a bit and makes perfect sense now.  Thx!


 
> And, please take this positively, but from your posted code it's fairly
> apparent that Python is not your native tongue :).  

Correct.  The barbarians invaded my homeland and forced me to speak their 
wicked incantations.  I'm a c/c++ guy through and through with a 
sprinkling of the ancient tongues like algol, LSI-11 and Z80 assembler, 
fortran-4, etc.

My python stuff is all rapid application development for personal 
projects.  If I need to do anything serious I take the time to do it in C+
+.


> For instance, you
> don't need the backslashes in your defaultparams assignment; the parser
> knows it needs to keep looking on subsequent lines when it hasn't found
> the closing '}' yet.  

It's the intendation specific requirements that throw me.  I haven't seen 
such a hork since RPG. ;^)


> Also, you can iterate over a (sys.argv) in a for
> loop, replacing 'l', 'idx', and the while loop; something like
> 
> for arg in a:
>     if arg == '-h':
>         print help # help being defined elsewhere...
>     elif arg == '-hh':
>         # no really, print help print 'help'

Understood, except that some parameters take multiple elements...thus why 
I manually reference the indexes.


> And the big one, argument parsing is a solved problem in Python. Check
> out the argparse module in the standard library (or if you're using an
> older version of Python, try either optparse or getopt.  It's really a
> thrice-solved problem ;)).

Yup.  Every language and platform has multiple arg parsing libraries.  
Didn't feel like taking the time to research any since most of my python 
ramblings are usually pyQT4 bindings to QT4 gui and postgresql apps.

> 
> I hope I've been of some help,

Pointing out that sys.exit() raises a low level exception was the point I 
was missing.  Thx!




More information about the Python-list mailing list