You can advise elpy-doc to achieve this goal. This runs a function after elpy-doc to turn on rst-mode in the Python Doc buffer it creates, but only when the word scipy is in the buffer.
(defun turn-on-rst-mode ()
(with-current-buffer "*Python Doc*"
(when (search-forward "scipy")
A quick-and-dirty keyboard macro called pydoc-rst bound to C-x C-k 1 and C-x C-k R for this purpose:
(kmacro-lambda-form [?\C-c ?\C-d ?\C-x ?o ?\M-x ?r ?s ?t ?- ?m ?o ?d ?e return ?\C-x ?o] 0 "%d"))
(global-set-key [24 11 82] 'pydoc-rst)
(global-set-key [24 11 49] 'pydoc-rst)
Let me know if this seems wrong somehow.
You might find what you are looking for here: How to make private python methods the last company-mode choices?
Here is a way I got strings to sort the way you described:
(sort '("_two" "_one" "__two" "__one" "one")
(lambda (s1 s2)
(if (and (string-prefix-p "_" s1)
I'm not so familar with elisp, but as aadcg pointed out that elpy-shell-switch-to-shell and delete-window might work I gave it a try.
(defun python-toggle ()
(cond ((equal (buffer-name) "*Python*") (delete-window))
((get-buffer "*Python*") (elpy-shell-switch-to-shell))
((derived-mode-p 'python-mode) (run-...