Function: python-add-import
python-add-import is an autoloaded, interactive and byte-compiled
function defined in python.el.gz.
Signature
(python-add-import NAME)
Documentation
Add an import statement to the current buffer.
Interactively, ask for an import statement using all imports found in the current project as suggestions. With a prefix argument, restrict the suggestions to imports defining the symbol at point. If there is only one such suggestion, act without asking.
When calling from Lisp, use a non-nil NAME to restrict the suggestions to imports defining NAME.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
;;;###autoload
(defun python-add-import (name)
"Add an import statement to the current buffer.
Interactively, ask for an import statement using all imports
found in the current project as suggestions. With a prefix
argument, restrict the suggestions to imports defining the symbol
at point. If there is only one such suggestion, act without
asking.
When calling from Lisp, use a non-nil NAME to restrict the
suggestions to imports defining NAME."
(interactive (list (when current-prefix-arg (thing-at-point 'symbol))))
(when-let ((statement (python--query-import name
(python--import-sources)
"Add import: ")))
(if (python--do-isort "--add" statement)
(message "Added `%s'" statement)
(message "(No changes in Python imports needed)"))))