First, choose Python in the language.
Then click Run, and in the Pop-up dialog box, enter:
Cmd/k cd/d "$ (current_directory)" & Python "$ (full_current_path)" & ECHO. & PAUSE & EXIT
Then click Save, enter the name of the shortcut key, such as Runpython, and then define the shortcut keys, such as Ctrl+f5. After writing the code, just press CTRL+F5 to run the program.
Explain:
Where cmd/k means to open the CMD command line and then run the command after/k
Cd/d "$ (current_directory)" in:
The CD command represents the switch to the current working directory
/d is a parameter to the CD command, which indicates that the directory you want to switch to is not on the same partition, plus/d, otherwise the CD will not pass.
$ (current_directory) represents the directory where the current source program files are located
& used to connect two commands, sequential execution
Python: Python can run directly to Python.exe because it previously set the path in the environment variable
$ (Full_current_path) refers to the full path of the current file
Echo: Line break
Pause: Indicates a pause after running (cmd displays "Press any key to continue ..."), waiting for a key to continue
Exit: Indicates "Press any key to continue ..." to close the command line window.
Because Python is a language that is sensitive to spaces and indents, you need to make the settings relevant.
First set the tab to 4 spaces, select Settings-Preferences, and then action. As shown in.
And then set--Other, select Auto Indent
Then select in the format utf-8 no BOM format encoding
Additionally, when you are finished programming, you may have errors such as the following indentation in the process of running:
Syntax error in Python script run: Indentationerror:unindent does not match any outer indentation level.
First of all, look at the error before and after the line, if and so on after the leakage of ":", or ":" After forgetting to indent.
Another possibility is that the tab and the space are mixed. Although we have already set the tab to automatically turn 4 spaces, it is sometimes possible to mix tab and space. Like copying and pasting code from somewhere else. This time select View-show symbol-Show all characters. The space is displayed as a point, and the tab appears as an arrow. As shown in.
Configuring the Python environment in notepad++