5

私は Emacs python-mode と ipython を IDE として使用して Python コードを記述しています。Python-mode は、1 行のコードを実行するための "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 コマンドを使用せずに「セル」の値を確認するより直接的な方法があるかどうか疑問に思っています。カーソルを変数に移動し、何らかのキーを押すと、値が 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)を試しましたが、出力が印刷されません...

前もって感謝します!

4

3 に答える 3

1

強調表示せずに、次を使用します。

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

存在する場合、現在の選択を選択するように簡単に適応できるはずです(

于 2020-08-28T13:36:57.887 に答える
0

たぶん、での機能リクエストを検討してください

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

于 2014-08-07T16:33:23.407 に答える
0

正確には望みどおりではありませんが、領域を強調表示して ( を押しC-SPCてマークをアクティブにし、領域の反対側に移動することによって)、M-|run と入力することができますshell-command-on-region。次にpython RET、リージョンで Python を実行するように入力します。

たとえば、次の 2 行を選択します。

message = "Hello, Stack Overflow!"
print message

次に、 と入力しM-| python RETます。「Hello, Stack Overflow!」というメッセージが画面の下部に表示されます。これは、どのモードでも、どのシェル コマンドでも実行できます。参照:シェル コマンド.

于 2014-08-06T18:18:58.950 に答える