Function: python-shell-send-file
python-shell-send-file is an interactive and byte-compiled function
defined in python.el.gz.
Signature
(python-shell-send-file FILE-NAME &optional PROCESS TEMP-FILE-NAME DELETE MSG)
Documentation
Send FILE-NAME to inferior Python PROCESS.
If TEMP-FILE-NAME is passed then that file is used for processing instead, while internally the shell will continue to use FILE-NAME. FILE-NAME can be remote, but TEMP-FILE-NAME must be in the same host as PROCESS. If TEMP-FILE-NAME and DELETE are non-nil, then TEMP-FILE-NAME is deleted after evaluation is performed.
When optional argument MSG is non-nil, forces display of a user-friendly message if there's no process running; defaults to t when called interactively.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-shell-send-file (file-name &optional process temp-file-name
delete msg)
"Send FILE-NAME to inferior Python PROCESS.
If TEMP-FILE-NAME is passed then that file is used for processing
instead, while internally the shell will continue to use
FILE-NAME. FILE-NAME can be remote, but TEMP-FILE-NAME must be
in the same host as PROCESS. If TEMP-FILE-NAME and DELETE are
non-nil, then TEMP-FILE-NAME is deleted after evaluation is
performed.
When optional argument MSG is non-nil, forces display of a
user-friendly message if there's no process running; defaults to
t when called interactively."
(interactive
(list
(read-file-name "File to send: ") ; file-name
nil ; process
nil ; temp-file-name
nil ; delete
t)) ; msg
(setq process (or process (python-shell-get-process-or-error msg)))
(with-current-buffer (process-buffer process)
(unless (or temp-file-name
(string= (file-remote-p file-name)
(file-remote-p default-directory)))
(setq delete t
temp-file-name (with-temp-buffer
(insert-file-contents file-name)
(python-shell--save-temp-file (current-buffer))))))
(let* ((file-name (file-local-name (expand-file-name file-name)))
(temp-file-name (when temp-file-name
(file-local-name (expand-file-name
temp-file-name)))))
(comint-send-string
process
(format
"__PYTHON_EL_eval_file(%s, %s, %s)\n"
(python-shell--encode-string file-name)
(python-shell--encode-string (or temp-file-name ""))
(if delete "True" "False")))))