python 2.7 - Conditional statement not redirecting like it should -
i'm new python , working on stript gets user input redirect part of program. i'm using conditional statement either go or exit. when press key continue exits. please help
def infomenu(): = ''' 1 = volume information 2 = volume status 3 = display peer status 4 = ctdb status 5 = ctdb ip 6 = display ctdb config file ''' print a = raw_input('enter option: ') if == '1': option = raw_input('please enter name of vol: ') subprocess.call(['gluster vol ', option, 'info'], shell=false) elif == '2': option = raw_input('please enter name of vol: ') subprocess.call(['gluster vol ', option, 'status'], shell=false) elif == '3': subprocess.call(['lvdisplay'], shell=false) answer = raw_input('press 0 go or exit (default[0]): ') if answer == '0': printoptions() else: exit() elif == '4': option = raw_input('please enter name of vol') subprocess.call(['gluster vol ', option, 'info'], shell=false) elif == '5': option = raw_input('please enter name of vol') subprocess.call(['gluster vol ', option, 'info'], shell=false) else: exit() i'm talking condition statement 3 when press 0 suppose go beginning menu , else should exit. doing wrong.
tracing code:
- function
infomenu()run - if user enters "3" (return)
- your
subprocess.callrun - then user asked new input
after code , description don't seem match, because if user enters "0", calling other function (which isn't included) called "printoptions()"
a super simple fix (that break if ever return) re-call infomenu in place of printoptions call, suspect better off better off rewriting.
if trying described (using style) do:
def infomenu(): def thing1(): pass #do_somethings() def thing2(): #do_someotherthings() user_input = raw_input('press 0 go or exit (default[0]): ') if (len(user_input)==0) or (user_input == '0'): return else: exit() a=""" 1 = thing1 2 = thing2 """ print user_input = raw_input('enter option') if user_input == '1': thing1() if user_input == '2': thing2() while 1: infomenu()
Comments
Post a Comment