3

In my terminal shell if I just evaluate, e.g. 3+3, I get

Python 3.6.1 (default, May 21 2017, 04:38:38) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 3+3
6
>>> 

However, using emacs' interactive shell and when evaluating code using python-shell-send-line or python-shell-send-region, I don't get any feedback on the code being executed (unless of course there is some print involved).

my relevant configuration in .emacs is just this:

(setq python-shell-interpreter "/opt/local/bin/python3.6"
      python-shell-interpreter-args "-i")
(add-hook 'python-mode-hook 'anaconda-mode)

I'm not sure whether it is related, but even though I do have readline installed (as you can see in the image), I also get this warning:

Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native’ was t and "python3.6" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally. 

enter image description here

I'd like to see some feedback on the code I execute. Any ideas?

1 Answer 1

1

I use the following bound to C-c C-c. It is just a simple hack to send a print statement if the line doesn't start with one, YMMV.

;; send current line, with prefix print result
(defun python--send-line (arg)
  (interactive "P")
  (if (not arg)
      (python-shell-send-region (line-beginning-position) (line-end-position))
    (save-excursion
      (beginning-of-line)
      (if (looking-at-p "\\s-*print")
          (python-shell-send-region (line-beginning-position)
                                    (line-end-position))
        (python-shell-send-string
         (concat "print(" (buffer-substring (line-beginning-position)
                                            (line-end-position))
                 ")")))))
  (display-buffer (process-buffer (python-shell-get-process))))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.