The question here is related (but NOT identical) and complementary to Change the "send code to interpreter" (C-c |) command in python-mode .
I work on a M
i did some hacking and here is what i have: by reading the code you should be able to tell how it works.
(defun block-line-end ()
(setq indentation (current-indentation))
(forward-line)
(while (> (current-indentation) indentation)
(forward-line))
(forward-line -1)
(line-end-position))
(defun my-python-shell-send-region (&optional beg end)
(interactive)
(let ((beg (cond (beg beg)
((region-active-p) (region-beginning))
(t (line-beginning-position))))
(end (cond (end end)
((region-active-p)
(copy-marker (region-end)))
(t (block-line-end)))))
(python-shell-send-region beg end))
(forward-line))