Re: Pop return from stack?

2010-08-29 Thread Aahz
In article 40a6bfac-3f4b-43f4-990b-224cb2b65...@i19g2000pro.googlegroups.com, Carl Banks pavlovevide...@gmail.com wrote: FWIW, I think it perfectly reasonable to let an application print a traceback on an error. I've gotten a few bug reports on a little tool I maintain where the user copies the

Re: Pop return from stack?

2010-08-21 Thread bvdp
On Aug 20, 6:41 pm, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: bvdp wrote: The whole problem I was having is that I was trying to tie a small application (an helper to the main application) to use a bit of the existing code as a pseudo-library. This is precisely the reason that it's

Re: Pop return from stack?

2010-08-20 Thread Gregory Ewing
bvdp wrote: The whole problem I was having is that I was trying to tie a small application (an helper to the main application) to use a bit of the existing code as a pseudo-library. This is precisely the reason that it's a bad idea to directly terminate the program from somewhere deep inside

Re: Pop return from stack?

2010-08-19 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : Oh my ... I've seen people writing Java in Python, C++ in Python, Perl in Python, even VB in Python, but this is the first time I've meet some one who wants to write assembler in Python :) +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: Pop return from stack?

2010-08-16 Thread Steven D'Aprano
On Sun, 15 Aug 2010 21:01:04 -0700, Carey Tilden wrote: On Sun, Aug 15, 2010 at 6:43 PM, bvdp b...@mellowood.ca wrote: Not to belabor the point .. but func is not a standard lib module. It's part of a much larger application ... and in that application it makes perfect sense to terminate

Re: Pop return from stack?

2010-08-16 Thread Steven D'Aprano
On Sun, 15 Aug 2010 18:43:49 -0700, bvdp wrote: [...] However, I have gotten hit with more than one comment like yours. So, could you please clarify? Is it bad form to exit an application with sys.exit(1) when an error in a file the application is processing is found? My two cents worth...

Re: Pop return from stack?

2010-08-16 Thread Carey Tilden
On Mon, Aug 16, 2010 at 4:18 AM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Sun, 15 Aug 2010 21:01:04 -0700, Carey Tilden wrote: On Sun, Aug 15, 2010 at 6:43 PM, bvdp b...@mellowood.ca wrote: Not to belabor the point .. but func is not a standard lib module. It's part of

Re: Pop return from stack?

2010-08-15 Thread Dave Angel
Steven D'Aprano wrote: On Sat, 14 Aug 2010 16:05:05 -0700, bvdp wrote: snip def error(s): print Error, s sys.exit(1) snip This general technique is called monkey patching. snip You can either manually exit from your own error handler: def myerror(s): print new error

Re: Pop return from stack?

2010-08-15 Thread John Nagle
On 8/14/2010 4:05 PM, bvdp wrote: Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing Fix func. That's terrible

Re: Pop return from stack?

2010-08-15 Thread bvdp
On Aug 15, 12:52 pm, John Nagle na...@animats.com wrote: On 8/14/2010 4:05 PM, bvdp wrote: Assuming I have a module 'foo.py' with something like this: def error(s):      print Error, s      sys.exit(1) def func(s):      ... do some processing      ... call error() if bad .. go to

Re: Pop return from stack?

2010-08-15 Thread Carey Tilden
On Sun, Aug 15, 2010 at 6:43 PM, bvdp b...@mellowood.ca wrote: Not to belabor the point .. but func is not a standard lib module. It's part of a much larger application ... and in that application it makes perfect sense to terminate the application if it encounters an error. I fail to see the

Re: Pop return from stack?

2010-08-15 Thread Carl Banks
On Aug 15, 6:43 pm, bvdp b...@mellowood.ca wrote: On Aug 15, 12:52 pm, John Nagle na...@animats.com wrote: On 8/14/2010 4:05 PM, bvdp wrote: Assuming I have a module 'foo.py' with something like this: def error(s):      print Error, s      sys.exit(1) def func(s):      

Pop return from stack?

2010-08-14 Thread bvdp
Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing and then I write a new program, test.py, which: import foo def

Re: Pop return from stack?

2010-08-14 Thread Thomas Jollans
On Sunday 15 August 2010, it occurred to bvdp to exclaim: Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing

Re: Pop return from stack?

2010-08-14 Thread Steven D'Aprano
On Sat, 14 Aug 2010 16:05:05 -0700, bvdp wrote: Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing and then I

Re: Pop return from stack?

2010-08-14 Thread Carl Banks
On Aug 14, 4:05 pm, bvdp b...@mellowood.ca wrote: Assuming I have a module 'foo.py' with something like this: def error(s):     print Error, s     sys.exit(1) def func(s):     ... do some processing     ... call error() if bad .. go to system exit.     ...  more processing and then I

Re: Pop return from stack?

2010-08-14 Thread Chris Rebert
On Sat, Aug 14, 2010 at 5:23 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: snip Oh my ... I've seen people writing Java in Python, C++ in Python, Perl in Python, even VB in Python, but this is the first time I've meet some one who wants to write assembler in Python :) +1 QOTW

Re: Pop return from stack?

2010-08-14 Thread bvdp
An exception will walk up the stack, calling any cleaning-up code that needs to be done (removing object references, executing finally: blocks, exiting context managers properly. It won't break anything. Don't be afraid of Python's high-level features! Okay, I believe you (and the rest of

Re: Pop return from stack?

2010-08-14 Thread bvdp
On Aug 14, 5:23 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: This general technique is called monkey patching. New term for me :) Now, if an error is encountered myerror() is called. Fine. But execution resumes in func(). Not exactly what I wanted. Of course it does.