如何 运行 "section" 的 python 脚本,比如 Matlab

How to run a "section" of a python script, like Matlab

在 python 脚本中使用 vim(或任何其他文本编辑器)时,是否可以单独 运行 脚本的一部分?

Matlab 有一个功能,以 %% 开头的一行会将后面的代码行拆分成自己的一部分,可以是 运行 独立的。有没有一种无需使用 iPython 即可实现此目的的方法?即使解决方案有点 hacky,它也会比我目前正在做的事情有所改进,即注释掉我不想 运行.

的块

通用解决方案是 vim-slime:https://github.com/jpalardy/vim-slime

SLIME is an Emacs plugin to turn Emacs into a Lisp IDE. You can type text in a file, send it to a live REPL, and avoid having to reload all your code every time you make a change.

Vim-slime is a humble attempt at getting some of these features into Vim. It works with any REPL and isn't tied to Lisp.