Will man in seinen python Scripts fragen ob weiter gemacht werden soll (ähnlich wie beim Installieren von Paketen in Paketmanagern) bietet sich diese F8unktion ans:
def ask_proceed(question, default="yes"): valid = {"yes":"yes", "y":"yes", "no":"no", "n":"no"} if default == None: prompt = " [y/n] " elif default == "yes": prompt = " [Y/n] " elif default == "no": prompt = " [y/N] " else: raise ValueError("invalid default answer: '%s'" % default) while 1: print (question + prompt) choice = raw_input().lower() if default is not None and choice == '': return default elif choice in valid.keys(): return valid[choice] else: print ("Please respond with 'yes' or 'no' (or 'y' or 'n').\n") result = ask_proceed("Do you want to continue?") if result == "yes": print "A good choise! I will continue with whatever I was doing..." if result == "no": print "Ok, bye!" |