> >> ## Can someone suggest a pythonesque way of doing this? >> >> >> def getid(): >> response = raw_input('prompt') >> if response not in [ "", "y", "Y", "yes"] : >> getid() # ouch >> print "continue working" >> # do more stuff >> # do more stuff >> This seems like really strange behavior. If the response is wrong, you will then have another instance of getid, then if they get the response correct, you will execute your code twice! Was that really your intent? I think what you really want is: def getid(): valid = False while not valid: response = raw_input('prompt') valid = response.strip().lower() in ["", "y", "yes"]
>One improvement - response.lower().startswith("yes") will cover all your cases. Am I misunderstanding? They appear to have different behaviors. >>> x = "" >>> y = ["", "y", "Y", "yes"] >>> x not in y False >>> x.lower().startswith('yes') False >>> x = "yes" >>> x not in y False >>> x.lower().startswith('yes') True _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor