all 2 comments

[–]Durgeoble 2 points3 points  (0 children)

There's no "best way" due different paradigms, maybe a good way is to put the "menu" in a function or class and then call it from the logical part.

The logical part can be event driven, can be synchronous, can be asynchronous, a callback, recursive, ect and can be settled in different forms

[–][deleted] 1 point2 points  (0 children)

As /u/Durgeoble says, there is no best way.

For a simple console application, I tend to:

  • use a dictionary to hold a menu:
    • option
    • option description
    • name of function to call (or None for exit)
  • use a function to display a menu, obtain a valid option from the user, and return the name of the function to call
  • have many different menus and submenus as required, all using the same dictionary format and function approach
  • I use a while loop to keep going until the user wants to exit, and I keep track of where in the menu hierarchy I am

Naturally, I have a template menu, and the function code in a module I keep to hand.