Why doesn't exec work in a function with a subfunction?
16:12 19 Dec 2010

It looks like you can't use exec in a function that has a subfunction...

Anyone know why this Python code doesn't work? I get an error at the exec in test2. Also, I know exec's aren't good style, but trust me, I'm using exec for an appropriate reason. I wouldn't use it otherwise.

#!/usr/bin/env python
#

def test1():
    exec('print "hi from test1"')

test1()

def test2():
    """Test with a subfunction."""
    exec('print "hi from test2"')
    def subfunction():
        return True

test2()

EDIT: I narrowed down the bug to having a function in a subfunction. It has nothing to do with the raise keyword.

exec python-2.x