Pop return from stack?
Carl Banks
pavlovevidence at gmail.com
Sat Aug 14 22:26:09 EDT 2010
On Aug 14, 4:05 pm, bvdp <b... at 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 write a new program, test.py, which:
>
> import foo
>
> def myerror(s):
> print "new error message"
>
> foo.error = myerror
>
> a = foo.func(..)
>
> Now, if an error is encountered myerror() is called. Fine. But
> execution resumes in func(). Not exactly what I wanted.
>
> I can "fix" this simply by wrapping the call to foo.func() in a try/
> expect and have myerror() raise an exception. This appears to work,
> but I'm hesitant to use this out of fear that I'm building up some
> kind of stack overflow or something which will bite me later.
What do you think a few words of data the stack are going to do?
Just do it this way.
Carl Banks
More information about the Python-list
mailing list