Solve the Pit of python3 Input input of

  • 2021-08-12 03:13:12
  • OfStack

As shown below:

a,b,c,d = input()

Very simple code, if the input is

1 -1 -2 3

The result will report an error because the input function will run your input as an python script, and the input will become

1-1-2 3, i.e. 0-2 3

The result is, of course, wrong. The solution is to enclose the input in quotation marks and enter it as a string.

I.e.

"1 -1 -2 3"

So the result is

a=1, b=-1, c=-2, d=3

Additional knowledge: Sublime Text3 in Python environment cannot use input () function

[Note]: The following operation process is the result of combining various network methods and then practicing by yourself. Written here, the main purpose is to deepen the memory, and also hope to help the latecomers stick out their tongues

Write Python program in Sublime Text3, press Ctrl+B to run the program, enter the content in the console, enter, the program does not respond. Finally, I turned to the network and found a solution.

1. Install plug-in SublimeREPL

1. Press Ctrl+Shift+P to open the command box. Enter Install Package, enter, wait for a few seconds, and a pop-up window will prompt "Installation succeeded".

2. Press Ctrl+Shift+P to open the command box, enter Install, select "Package Control: Install Package", then enter SublimeREPL in the new command box, and enter

Step 2 Run the program

Click Tools-SublimeREPL-Python-Python-RUN current file in turn to open a file named "* REPL* [python]", which is interactive. Enter the contents in it and enter.

3. Set shortcut keys to run

Click Preferences-Key Buildings in turn, enter the following contents, then save, and set the key F5 as the shortcut key for running the program


[
 { "keys": ["f5"], "caption": "SublimeREPL:Python", 
      "command": "run_existing_window_command", "args":
      {
       "id": "repl_python_run",
       "file": "config/Python/Main.sublime-menu"
      } 
 },
]

Related articles: