I'm trying to declare two functions within exec statement in python. Let's call them f1() and f2().
I've found out that when exec is invoked inside of some function, then f2() has no visibility of f1(). However this doesn't happen when exec and function call are placed in global code.
# Case 1: Working fine
code = """
def f1(): print "bar"
def f2(): f1()
"""
exec(code)
f2() # Prints "bar" as expected
Run Code Online (Sandbox Code Playgroud)
# Case 2: Throws NameError: …Run Code Online (Sandbox Code Playgroud)