emacs - 在 Emacs python 模式下执行表达式并打印其值

标签 emacs ipython python-mode

我使用 Emacs python-mode 和 ipython 作为我的 IDE 来编写 python 代码。 Python 模式提供了一个很好的函数“py-execute-line”来运行一行代码,我已将其绑定(bind)到键“F7”。

因此对于以下代码:

cell = "Human" #  Move the cursor to this line and run it by pressing F7
print cell     #  Move the cursor to this line and run it by pressing F7

我可以在 ipython 缓冲区中打印输出。

In [80]: 
In [81]: Human

我想知道是否有更直接的方法来检查“单元格”的值而不使用打印命令。比如将光标移动到变量,按某个键,然后将值打印在 ipython 输出缓冲区中。

cell = "Human" #  Move the cursor to this line and run it by pressing F7
cell = "Human" #  Move the cursor to "cell" and print its value by pressing ?? key or function

我尝试过函数(py-execute-expression-ipython),但没有打印输出...

提前致谢!

最佳答案

没有突出显示,我使用:

(defun python-eval-expression ()
  (interactive)
  (let ((py-command (read-string "Command: ")))
    (save-excursion
      (setq elpy-shell-echo-output t)
      (setq elpy-shell-echo-input t)
      (elpy-shell--with-maybe-echo (python-shell-send-string py-command)))))

应该很容易适应选择当前选择(如果存在)(使用

关于emacs - 在 Emacs python 模式下执行表达式并打印其值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25166991/

相关文章:

python, ipython运行交互脚本

python - 如何在Python中计算一组值的密度分布?

emacs - 何时在 Emacs Lisp 中引用符号

Emacs 中的 Python 类型提示

emacs - 拆分窗口时控制 Emacs 行为

Emacs:如何在 python 模式下自动启动 python 解释器?

python - emacs windows 在当前缓冲区中运行 python 程序并在输出窗口中显示输出

emacs - emacs摆脱了C-x

python - Pycharm IPython 选项卡完成不起作用(在 python 控制台中)

vim、病原体和 ftplugin 文件的加载顺序