emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Extraneous output from Python code blocks using :session option


From: Nicolas Goaziou
Subject: Re: [O] Extraneous output from Python code blocks using :session option
Date: Fri, 13 Mar 2015 09:21:09 +0100

Hello,

Kyle Meyer <address@hidden> writes:

> I've attached two patches.  The first one is a proposed way to deal with
> the indentation issues in sessions.  It is very similar to what
> python.el does for multiline input (use a temporary file and then
> execute that from the shell).  The second is an update of my previous
> patch to remove shell prompt characters that are leaking into the
> output.

Thank you.

I'll just comment about code, not functionality.

> +(defconst org-babel-python-indented-lines-session-method
> +  (concat "fname= '%s'; fh = open(fname); "
> +       "exec(compile(fh.read(), fname, 'exec')); "
> +       "fh.close()")
> +  "Single line to execute indented Python code in session.
> +%s will be formatted with the file name of the file containing
> + the code.")
  ^^^
spurious space

> +(defun org-babel-python--indented-p (input)
> +  "Return true if any line in INPUT is indented."

Non-nil if ...

> +  (with-temp-buffer
> +    (insert input)
> +    (goto-char (point-min))
> +    (re-search-forward "^\\s-" nil t)))

aka

  (org-string-match-p "^[ \t]" input)

> +(defun org-babel-python--strip-session-chars (string)
> +  "Remove leading '>>>' and '...' from Python session output.
> +`org-babel-comint-with-output' splits by
> +`comint-prompt-regexp' (which includes '>>>' and '...'), but, in
> +some situations, these still make it through at the start of the
> +output string."

Argument STRING is not explained in the docstring.

> +  (with-temp-buffer
> +    (insert string)
> +    (goto-char (point-min))
> +    (when (looking-at "\\s-*\n\\(\\(>>> \\)\\|\\(\\.\\.\\. \\)\\)*")
> +      (delete-region (match-beginning 0) (match-end 0)))
> +    (buffer-string)))

aka

  (replace-regexp-in-string "\\`\\s-*\n\\(>>> \\|\\.\\.\\. \\)*" "" string)


Regards,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]