emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jack Kamm <jackkamm@gmail.com>
To: numbchild@gmail.com, Org Mode <emacs-orgmode@gnu.org>
Subject: Re: Make ob-python.el support ":results pp" pretty print result
Date: Sat, 22 Feb 2020 09:21:12 -0800	[thread overview]
Message-ID: <87r1ymk06v.fsf@gmail.com> (raw)
In-Reply-To: <87y2sx6yvl.fsf@gmail.com>

Hi stardiviner,

stardiviner <numbchild@gmail.com> writes:

> I found ob-python does not support ":results pp" pretty print result. And Python
> has a module "pprint". What about add support this?

":results pp" works for me, here's an example:

> #+begin_src python :results pp
>   return globals()
> #+end_src
> 
> #+RESULTS:
> #+begin_example
> {'__annotations__': {},
>  '__builtins__': <module 'builtins' (built-in)>,
>  '__cached__': None,
>  '__doc__': None,
>  '__file__': '<stdin>',
>  '__loader__': <class '_frozen_importlib.BuiltinImporter'>,
>  '__name__': '__main__',
>  '__package__': None,
>  '__spec__': None,
>  'main': <function main at 0x7f8347f28ee0>,
>  'pprint': <module 'pprint' from '/usr/lib/python3.8/pprint.py'>}
> #+end_example

Here's how it looks by default (without "pp"):

> #+begin_src python
>   return globals()
> #+end_src
> 
> #+RESULTS:
> | __name__ | : | __main__ | __doc__ | : | hline | __package__ | : | hline | __loader__ | : | <class | _frozen_importlib.BuiltinImporter | > | __spec__ | : | hline | __annotations__ | : | nil | __builtins__ | : | <module | builtins | (built-in) | > | __file__ | : | <stdin> | __cached__ | : | hline | main | : | <function | main | at | 0x7f63ea83bee0> |

And here's how it looks when using ":results output":

> #+begin_src python :results output
>   print(globals())
> #+end_src
> 
> #+RESULTS:
> : {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': '<stdin>', '__cached__': None}

I also tested this on ":session" blocks and the results were the same.

      parent reply	other threads:[~2020-02-22 17:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-20 15:51 Make ob-python.el support ":results pp" pretty print result stardiviner
2020-02-20 16:56 ` Jack Kamm
2020-02-22 17:21 ` Jack Kamm [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1ymk06v.fsf@gmail.com \
    --to=jackkamm@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=numbchild@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).