One option (ha!) is to store the structure of the options in a variable.
For example, (in your mind) define "a menu" as a dict which contains some subset of these values:
- "question" - this is the question to ask when showing the menu - "Choose B Subfunctions"
- "description" - this is the option you selected to get to this menu - for example, for the "Choose B suboptions", this would be "B" - the answer you chose to get here. The first menu won't have this.
- "suboptions" - this is a list of of menus from here.
- "code" - if this exists, rather than showing this menu, run this code.
for the example you gave above
def function_for_A1():
print "You chose A1!"
menus={"question":"Choose function Options","answers":[
{"description":"A","question":"Choose A Subfunctions","answers":[
{"description":"A1","code":function_for_A1},
{"description":"A2","code":function_for_A2},
]},
{"description":"B","question":"Choose B Subfunctions","answers":[
{"description":"B1","code":function_for_A1},
{"description":"B2","question":"B2 sub-suboption","answers":[...]},
]},
}
Once you have this structure, given the current menu, displaying it is fairly easy - run the code (if it exists), otherwise display the question, and for each of the answers display a number and the "description". Once they select a number, find the menu, wash, rince, repeat. You could make the menu function recursive, so if they select "0 - back", then you return from the current function.
Done!