Python: how to use a list as a source of choice for user input?

Can anyone check this code and tell me what is wrong?

input_list = ["One", "Two", "Three"]
P1 = input("Select the input: ", input_list[0], input_list[1], input_list[2])
print (P1)
+4
source share
3 answers

With python, raw_inputit is not possible to select a pre-selected list for the user. With raw_inputwe collect raw strings.

update : a good solution is to use a new selection library: https://github.com/wong2/pick It provides a little curses to select our selection from a specific list. Get it with pip install pick. (update: multi-select: yes)

update 2: python lib! https://curses-menu.readthedocs.org/en/latest/usage.html#getting-a-selection ( )

, , picker (multi-select: yes).

, , :

  • dialog - , , Debian, ,
  • selecta - , , ,
  • zenity ( yad-dialog) ( ). :

    zenity --list --text="a title" --column="first column" "first choice" "second choice"
    

    .

  • , GUI, gooey ( python script ) Flexxx , .
+9

,

P1 = input("Select the input: ", input_list[0], input_list[1], input_list[2])

TypeError: input expected at most 1 arguments, got 4, ,

+ .join :

P1 = input("Select the input: " + ' '.join(input_list) + "\n")

python 3, python 2, raw_input input, input , , NameError

0

input: https://docs.python.org/2/library/functions.html#input

inputRepresents a query and evaluates the data entered by the user as if it were a Python expression. If you just want to collect user input, use instead raw_input. You will need to implement custom logic to make sure that the user input matches something from your list.

0
source

All Articles