1

https://i.stack.imgur.com/TIxlR.png

The picture shows what I mean by "block" - I mean a cell of code that is delimited by some sequence of characters, in this case '#%%', that can be executed by the python/IPython console when the user types some keybinding while the cursor is in that cell.

It's very useful for interactive/explorative work because you can break your code up into logical chunks where each part can be worked on iteratively without running the entire script each time.

So if one part of my code ingests a large data frame and another part analyzes it, I can put each part in different cells so that while I'm playing around with how to best interpret the data I don't have to keep reloading the data frame on each iteration.

If emacs can do this kind of block/cell execution, I will wholly devote myself to its religion. Right now I know of a few possible ways in vim, but suffice it to say they are all terrible.

  • I've never used it, but I just read about isend (github.com/ffevotte/isend-mode.el). Also, definitely check out python-mode's built in evaluation mechanisms and org babel (with sessions). – jpkotta Feb 15 '18 at 7:39
  • was just thinking about this. Did you ever come up with anything? – Vince W. Sep 19 '18 at 0:06
1

I use ein, which stands for emacs ipython notebook. It is the jupyter notebook implementation for emacs. See ein doc. Just like jupyter you execute cells and get back the output. The cells are saved in the notebook, so it is very useful and functional.

You can also use org-babel, look at babel-doc And so save the cells in org files, also very functional.

0

I've not personally done this with python, but there are several options.

Org-mode lets you create a file containing source-code blocks and allows you to execute those blocks on demand. See chapter 14 of the org-mode manual for all of the details. You can mix source blocks of many languages in a single file, which is often nice.

There are other ways to access a more traditional Python REPL inside of Emacs, however. The Emacs Wiki has much information on this and related subjects.

I'm sure one of these can meet your needs.

0

You can open a python process with M-x run-python or C-c C-p.

Select the region (block) you want to execute and do a M-x python-shell-send-region or C-c C-r

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.