Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

notepad++ run selected code in python console seamlessly

I often use R to analyze data, and really enjoy Notepad++ along with NppToR. Especially, NppToR enables to run a part of code without much hassle. I just highlight a snippet of R code to run and press F8. Then the code magically runs in R console.

Now, I am required to use python to analyze data. I know that ipython is great to work interactively, but it is always very annoying to copy a snippet of python code and manually paste that into ipython console. Also, indentation is often mixed and thus the entire lines are failed to run. Note that I want to run 'selected' lines of codes, not the entire file.

So I am looking for a program/plugin/macro similar to NppToR, but working with python/ipython console. I have searched the web, but couldn't find such one. Some plugins are nice, but not exactly what I want. For example, Python Script enables extending Notepad++ itself, but not outside. Various other 'Run' extensions enables the entire file to be run in python.

like image 531
xosp7tom Avatar asked Oct 14 '11 18:10

xosp7tom


People also ask

How do I run Python in Notepad ++ console?

To run the Python file from the notepad++ text editor, you have to click on the Run option from the menu and then choose the first option - Run... from the dropdown menu. It will open a new window on the screen, as shown below. Alternatively, You can also press the F5 key on the keyboard to open this window.

How do you write Python code in Notepad ++ and run?

Open Notepad++ On the menu go to: Run → Run.. (F5) Type in: cmd /K python "$(FULL_CURRENT_PATH)"

Can we use Notepad ++ for Python?

Python Editor: Notepad++ Notepad++ is a highly functional, free, open-source, editor for MS Windows that can recognize (i.e., highlight syntax for) several different programming languages from Assembly to XML, and many others inbetween, including, of course, Python.


1 Answers

You can customize the editor IPython uses for the edit command, and configure IPython to use Notepad++. IPython 0.11 creates a .ipython/profile_default folder in your user folder (in my case C:/Users/zk/.ipython/profile_default). To configure IPython to use Notepad++ create .ipython/profile_default/ipython_config.py with the following:

c = get_config()
# use DOS style path, C:/PROGRA~2 on my 64-bit system points to C:/Program Files (x86)
c.TerminalInteractiveShell.editor = 'C:\PROGRA~2\NOTEPA~1\NOTEPA~1.exe'
# set editor for Qt Console, if you wish to use that
c.IPythonWidget.editor = 'C:\PROGRA~2\NOTEPA~1\NOTEPA~1.exe'

You can then start up IPython and use the edit command to run Notepad++ from IPython, saving and closing Notepad++ will execute the file in IPython.

If you don't mind installing PyQt4 and pyzmq (and I believe pygments, at least for IPython 0.12-dev), IPython's Qt console works really well (frankly the nicest interactive environment you can get for Python). You can paste directly into IPython and it'll adjust indentation for you (shifting over padded code).

like image 69
zeekay Avatar answered Oct 22 '22 23:10

zeekay