In python, one would usually define a main function, in order to allow the script to be used as module (if needed):
def main(): print(\"Hello world\")
Maybe you can just deal with the debug library, with the debug.getinfo() function
if debug.getinfo(1).what == "main" then -- Main execution end
See the reference manual for more information.