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

在Emacs python模式下执行表达式并打印其值,emacs,ipython,python-mode,Emacs,Ipython,Python Mode,我使用Emacs python模式和ipython作为IDE来编写python代码。Python模式提供了一个很好的函数“py execute line”来运行单行代码,我已经将它绑定到键“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 pressi

我使用Emacs python模式和ipython作为IDE来编写python代码。Python模式提供了一个很好的函数“py execute line”来运行单行代码,我已经将它绑定到键“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
我想知道是否有更直接的方法可以在不使用print命令的情况下检查“cell”的值。类似于将光标移动到变量,按某个键,然后将值打印到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执行表达式ipython),但没有输出打印


提前谢谢

不完全是您想要的,但是您可以高亮显示一个区域(通过按
C-SPC
激活标记并移动到区域的另一侧),然后键入
M-|
在区域上运行
shell命令
。然后只需键入
pythonret
即可在该区域上运行python

例如,选择以下两行:

message = "Hello, Stack Overflow!"
print message

然后键入
M-| python RET
`你好,堆栈溢出!“将在屏幕的底部显示消息。您可以在任何模式下使用任何shell命令来执行此操作。参见:

< P>。请考虑在

中的特征请求。

在不突出显示的情况下,我使用:

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

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

谢谢。如果我理解正确,在这个解决方案中,print命令是必要的。添加print语句有时很烦人。在Rstudio中,有“ctr+R”来运行行或打印所选变量。python模式可以完成一半的工作(运行一行),我只需要另一半(检查变量值,不使用print语句)。谢谢,我稍后会做。