Execute the expression and print its value in Emacs python mode

I am using Emacs python-mode and ipython as my IDE to write python code. Python mode provides a nice "py-execute-line" function to run one code of a line, and I bound it to the "F7" key.

So for the following code:

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

      

I can get the output printed in the ipython buffer.

In [80]: 
In [81]: Human

      

I'm wondering if there is a more direct way to check the value of a "cell" without a print command. Something like moving the cursor to a variable, press a key and then the value will be printed to the ipython output buffer.

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

      

I tried the function (py-execute-expression-ipython) but no output printed ...

Thanks in advance!

+3


source to share


2 answers


Maybe consider a feature request in



https://bugs.launchpad.net/python-mode

0


source


Not what you want, but you can select an area (by clicking C-SPC

to activate the label and go to the other side of the area) and then enter M-|

to launch shell-command-on-region

. Then just type python RET

to run Python in the scope.

For example, select the following two lines:



message = "Hello, Stack Overflow!"
print message

      

Then enter M-| python RET

. "Hello, Stack Overflow!" It will appear as a message at the bottom of the screen. You can do this in any mode with any shell command. See also: Shell Commands .

0


source







All Articles