Global goto (magic word)

I am developing a program that reads user input within different functions. If the user types a magic word (say "restart"), I want to go to a specific location in my main module. I can do that by replacing the main code by a function -- say "my_main_code_function(restart_flag) -- that calls my main code and call it again if the user typed the magic word. While I am new to Python, I suspect that the stack will keep on growing each time the user chooses this option.

Is there a more elegant way to do that?

Hmm, it's hard to say without seeing more of the code -- but yes, it does sound like your solution would keep the stack growing.

Could you post a bit more of the code you have right now?

Thanks Giles. Appreciate you reaching out. I have decided to deploy a different approach. I am breaking the main code into smaller functions and will use a graph like object that will maintain the user location within the landscape and where they want to go next.

That sounds like a good approach :-)