Nested functions of Python pitfall and python pitfall nesting
Note that Python is an interpreted language. function A can call function B if function B is not defined before function A is defined.
Def func1 (): print "Hello fun1" fun2 () def func2 (): print "Hello func2" fun1 ()
This is fine. But imagine if function 2 also calls function 1?
As follows:
Def func1 (): print "Hello fun1" fun2 () def func2 (): print "Hello func2" fun1 () fun1 ()
This is a nested call. Stack explosion...
Because it is not a compilation language, it is difficult to analyze this problem using syntax in advance. It is very likely that python will not analyze this error for the sake of speed.
Therefore, when writing a program, pay special attention not to nested calls between two or more functions...
Of course, I didn't do this. I just tried it. It turns out that python can actually define nested functions.