leo wrote: > > You're absolutely right, in fact the code snippet from my OP was taken > directly from inspect.currentframe. We're intending on using this in > production, and I'm trying to gauge what the implications may be.
Use sys._getframe() instead; it doesn't raise an exception. > Wow, I was unaware of this. If Python internally uses exceptions, maybe > they aren't as detrimental as I thought. Exceptions raised from C code and caught by C code use considerably less resources, so a "for" loop catching a StopIteration raised by a built-in iterator will have better performance than Python code catching an exception raised in Python code. So, it's not necessarily the case that the "for" loop scenario matches your scenario(s). Always measure. -- http://mail.python.org/mailman/listinfo/python-list