[Baypiggies] running code in different stack frame

Shannon -jj Behrens jjinux at gmail.com
Fri Oct 8 02:03:53 CEST 2010

Raise and catch an exception. Use the exception to get a hold of the
caller's stack frame so you can play with its locals. I used this trick once
to implement a templating library called evalstr.

On Oct 7, 2010 2:12 PM, "Nick S Kanakakorn" <bbdada at gmail.com> wrote:


Is there anyway to specify that I want a block or function to work in
different stack frame in python ?
I'm thinking about something like this:

def check_something(magic_stack_frame, blah):
    if blah > 10
      return "Error...."
      # do something

def myf():
   blah = 20
   check_something(current_stack_frame, blah)
   print('should not be here')

In this case, I don't want to see the message 'should not be here'.  The
return "Error ...." should be done as if check_something
is in the same stack frame of myf() instead of check_something


-Nick Kanakakorn

Baypiggies mailing list
Baypiggies at python.org
To change your subscription options or unsubscribe:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20101007/623afa21/attachment.html>

More information about the Baypiggies mailing list