Emacs: Open Python Doc 📜

By Xah Lee. Date: . Last updated: .

here's a convenient command to open the python doc.

(defvar xah-python-doc-path
  (list "~/AppData/Local/Python/pythoncore-3.14-64/Doc/html/index.html")
  "A list of file full paths to python doc in HTML, used by `xah-python-open-doc'.
Each element is checked to see if it exist. (this is useful if you have multiple machines with different operating systems.).
On Windows Python 3.9, it's a .chm file, not supported by this command.
URL `http://xahlee.info/emacs/emacs/emacs_open_python_doc.html'
")
(defun xah-python-open-doc ()
  "Open python doc file `xah-python-doc-path'.
URL `http://xahlee.info/emacs/emacs/emacs_open_python_doc.html'
Created: 2023-03-18
Version: 2024-11-19"
  (interactive)
  (let ((xpath (seq-some
                (lambda (x)
                  (if (file-exists-p x) x nil))
                xah-python-doc-path)))
    (cond
     ((not xpath) (message "no file exists in paths `xah-python-doc-path' %s" xah-python-doc-path) nil)
     ((string-equal (file-name-extension xpath) "html") (browse-url xpath))
     (t
      (message "file exist at %s but is not HTML suffix." xpath)
      nil))))