notepad++ Configuring the Python development environment

Source: Internet
Author: User
Tags python script


1. Install Python


1 Downloads



I chose the 32-bit version of 2.7. Https://www.python.org/ftp/python/2.7.8/python-2.7.8.msi



2. Installation



Installation can be modified to modify the installation path to the D drive, and then note that the last item "Configuration environment variable" can be checked (default is not selected), 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 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 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 that the end of the run is paused (cmd displays " Press any key to continue ..." ), wait for a key to continue



EXIT: means " Press any key to continue ..." , 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 OS print 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 CD "(current_directory)" & ECHOPAUSEEXIT


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 osprint os.getcwd ()


Printing the current working directory is still "D:\Program Files (x86) \notepad++".



The problem is not solved.


Reference:


"1" How to configure the Python development environment in notepad++ (http://glorywu.com/How to configure the Python development environment in notepad++/)
"2" notepad++ a small improvement in the Python development environment (http://www.cnblogs.com/tt-0411/archive/2011/10/30/2229544.html)






notepad++ Configuring the Python development environment


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.