In python, I thought methods and functions had to be defined in the code before they were called. For example, we always define a subscriber callback function before we instantiate the subscriber (which uses the callback as a parameter).
However, in a recent project my callback function called several “helper functions” that were defined later in the code. The structure looked something like:
def callback(msg): help_function1() help_function2() help_function3() def help_function1() ... def help_function2() ... def help_function3() ... ... sub = rospy.Subscriber("/foo", Bar, callback)
Because this worked without any error, I didn’t realize until afterward this confilicted with what I thought was a rule of python. Are there certain cases where this won’t work? Obviously variables have to be previously declared, but is this not true for functions?
Does anyone have any insight on this?