1 Downloads
I chose the 32-bit version of 2.7.
2. Installation
You can modify the installation path at installation, and note that the last item "Configure environment variables" can be checked (by default) so that you do not have to manually configure environment variables.
2. Configure notepad++
You can refer to the article "1" method to configure, but note that the input command is reference to the article "2".
1. notepad++, run menu, run button
2. Enter the following command in the popup window:
cmd/k python "$ (full_current_path)" & ECHO. & PAUSE & EXIT
Then click "Save", feel free to take a name, such as "Runpython", for convenience, configure the shortcut keys (such as Ctrl + F5), click OK. Then run the Python file simply by pressing the configured shortcut key or by clicking "Runpython" on the Run menu.
Be careful not to conflict with existing shortcut keys. To view existing shortcuts, click the Manage Shortcut button on the Run menu to view
3. Order Explanation "1"
cmd/k python "$ (full_current_path)" & ECHO. & PAUSE & EXIT
cmd/k python: Opens the cmd window, runs the command behind/k, and retains the window after execution is complete. This is Python (because the Python directory has been added to the environment variable, so it is not necessary to specify a directory for the Python program, which can be found directly)
$ (Full_current_path): notepad++ macro definition that represents the full path of the current file.
& used to connect more than one command
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.
4. Meaning of the notepad++ macro definition
You can refer to the help documentation that comes with notepad++.
Click "? menu, Help button (or Shift+f1 shortcut), click on the right "Commands" in the open page to see what each macro definition means
FULL_CURRENT_PATH the fully qualified path to the current document. CURRENT_DIRECTORY The directory the current document resides in.
FILE_NAME
The filename of the document, without the directory.
NAME_PART
The filename without the extension.
EXT_PART
The extension of the current document.
NPP_DIRECTORY
The directory that contains the notepad++.exe executable that is currently running.
CURRENT_WORD
The currently selected text in the document.
CURRENT_LINE
The current line number that is selected in the document (0 based index, the first line is 0).
CURRENT_COLUMN
The current column the cursor resides in (0 based index, the first position on the line is 0).
5 Testing
Create a test file and save it as demorun.py.
import platform;
print "Just for demo how to do python development under windows:";
print "Current python version info is %s"%(platform.python_version());
print "uname=",platform.uname();
Ctrl + F5 executes to see if the results can be output.
3. Questions
1. When a Python script needs to create a file or directory, execute the script, find the file or directory that is not generated in the directory where the script is located, and find the resulting file in the notepad++ installation directory. For example, in the following script, you want to create a subdirectory "TestDir" in the directory where the script is located.
# create directory
import os
CurPath = os.path.abspath(‘.‘)
print CurPath
JoinPath = os.path.join( CurPath, ‘testdir‘)
print JoinPath
os.mkdir( JoinPath )
Found in the directory where the script is located, and under D:\Program Files (x86) \notepad++ generates a "TestDir" folder.
2. What is the reason? The article "2" did a small test, using the following code to print the current working directory:
Import Osprint OS.GETCWD ()
The installation directory for notepad++ is displayed, so it is determined that the working directory is a problem. The improved command line is:
cmd/k CD "(current_directory)" & Python "(Full_current_path)" & ECHO. & PAUSE & EXIT
The command line means: first CD to the directory where the Python script is to be executed (current_directory), in which the Python program executes, so that the working directory is the default notepad++ installation directory, Change to the directory where the Python script that you want to execute is located.
3. Modify the command line
If you want to modify the original command line to the improved command line, you find that notepad++ does not provide the modified functionality
cmd/k python "$ (full_current_path)" & ECHO. & PAUSE & EXIT
-
cmd/k CD "(current_directory)" & Python "(Full_current_path)" & ECHO. & PAUSE & EXIT
There are 2 ways to change.
(1) After clicking the "Manage Shortcut" button on the "Run" menu, delete the original shortcut and re-build it again.
(2) Modify the Shortcuts.xml. Note that the path to Shortcuts.xml may be shortcuts.xml under "c:\users\xxx\appdata\roaming\notepad++", rather than "D:\Program Files (x86) \ notepad++ "under the Shortcuts.xml
4. There is, however, a problem where the improved command line fails if the directory where the Python script resides and the notepad++ installation directory are no longer partitioned. For example, notepad++ is installed on the D drive and the script to execute is on the E drive, then run the following test script:
import os
print os.getcwd()
notepad++ Configuring the Python development environment