On Fri, Mar 20, 2009 at 1:32 AM, <el...@cmbi.ru.nl> wrote: > Hi everyone, > > is there a sufficiently easy possibility for a Python function to find > out whether it has been called from a try-block or not? > > try: > print "Calling foo" > foo() > except: > print "Got exception" > > In the example above, foo() should be able to 'see' that it was called > from a try block, allowing it to behave differently. > > Can this information be obtained from the traceback/frame/code > objects, or is that too difficult?
It might be possible, but it seems like there ought to be a better way to accomplish your goal. Could you explain why you want to do this in the first place? Perhaps a better alternative can be found. Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list