When sending an indented cell (e.g. a block in a method of a class), Python shell would throw IndentationError: unexpected indent
I figured out a hack to fix this problem( by prefixing a line 'if True:\n'):
(defunpython-shell-send-cell ()
"Send the cell the cursor is in to the inferior Python process."
(interactive)
(let* (
(start (save-excursion (python-beginning-of-cell)
(point)))
(end (save-excursion (python-end-of-cell)
(point)))
(content (buffer-substringstartend))
(preline"if True:\n")
(line-num (line-number-at-posstart))
;; Whensendingaregion, addblanklinesfornonsentcodeso
;; backtracesremaincorrect. (postline (make-string (1-line-num) ?\n)))
;;(message"DEBUG: %s" (substringcontent04))
(python-shell-send-string (concat (if (string= (substringcontent02) " ")
preline"")
contentpostline))))
When sending an indented cell (e.g. a block in a method of a class), Python shell would throw
IndentationError: unexpected indentI figured out a hack to fix this problem( by prefixing a line 'if True:\n'):