开发者

notepad++ run selected code in python console seamlessly

开发者 https://www.devze.com 2023-04-13 07:03 出处:网络
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

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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消