Skip to content

Error occurred when sending an indented cell #3

Description

@bamanzi

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))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions