-3

I am currently working on an automation task. I have arrived at a part of the script where I need confirmation from the user to continue. For example the script is automatically entering some values in Selenium for the user however I need confirmation from the user that these are the correct variables. Let's say I want to output this list into the command prompt:

['ESPN', 'ESPN Radio', 'ESPNews', 'ESPN2', 'ESPN3']

The user then can enter 'ESPN2' and my script will continue with the rest of its processes. How would I go about implementing the first portion of this? I believe the second portion of this task would involve using sys.argv[0] to correctly store the value the user enters back. However the issue is with the first part, how do I implement this so that my script knows to pause and wait for the user input? Thanks!

gold_cy
  • 13,648
  • 3
  • 23
  • 45

1 Answers1

0

IIUC you need to wait for the user until it matches your list.

Also make sure that you go through below link and reads the basics https://docs.python.org/3/

lst=['ESPN', 'ESPN Radio', 'ESPNews', 'ESPN2', 'ESPN3']
print lst


while True:
    value=raw_input("enter a value from list\n")
    if value not in ('ESPN', 'ESPN Radio', 'ESPNews', 'ESPN2', 'ESPN3'):
        print("Not an appropriate choice.")
    else:
        print("Continue to other modules")
        break

output

    ['ESPN', 'ESPN Radio', 'ESPNews', 'ESPN2', 'ESPN3']

    enter a value from list
    xx
    Not an appropriate choice.

    enter a value from list
    yy
    Not an appropriate choice.

    enter a value from list
    ESPN
    Continue to other modules
Shijo
  • 9,313
  • 3
  • 19
  • 31
  • 1
    If you use python 3, replace `raw_input()` with `input()` – Håken Lid Jan 26 '17 at 19:07
  • I'm using Python 2.7 but thanks. I thought I needed to use `sys` for this, I guess the only thing I need it for is to store the value they enter, is that correct? – gold_cy Jan 26 '17 at 19:21
  • Yes you are right. execute the script and let me know if this behaving as expected – Shijo Jan 26 '17 at 19:22