1

I want to give input yes/no automatically rather than through keyboard/user input.

user_choice = raw_input("Are you sure want to remove all item (y/n):\n")
if user_choice in('y','Y'):
    statement...
else:
    sys.exit(0)`
2
  • 2
    Why are you using input in the first place if you want to automatically assign an input? Commented Apr 7, 2016 at 12:40
  • Actually above function is used in somewhere and user input is necessary but in other hand I am using this function in another one and that time user interaction is not required. Commented Apr 7, 2016 at 12:44

1 Answer 1

2

you could pass in a flag to your function if you want to bypass the user input and do something like

def some_function(flag=None):
    user_choice = 'y' if flag else raw_input("Are you sure want to remove all item (y/n):\n")
    if user_choice in('y','Y'):
        statement...
    else:
        sys.exit(0)`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.