emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Make ob-python.el support ":results pp" pretty print result
@ 2020-02-20 15:51 stardiviner
  2020-02-20 16:56 ` Jack Kamm
  2020-02-22 17:21 ` Jack Kamm
  0 siblings, 2 replies; 3+ messages in thread
From: stardiviner @ 2020-02-20 15:51 UTC (permalink / raw)
  To: Org Mode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


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

- -- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      
-----BEGIN PGP SIGNATURE-----

iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5Oqu4UHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsM3gQgAn8oTYDwb1SvETMrOsOyfFnzXrbr1
i77t376xloPALkNUnmMj3myU7g13yKgYS04O5Lngki/Pb1jeQqFcua8BP76UDPJ/
V+u9VQGQ4CbBVoPD+fpsSri3hEpmSq/pw8SWGxXUoBbffozc7weDBqwvdwGdovuS
8UbbrQ9GVSKQkYGC2bW9/P7459urSzAUVuH838bq8ACGdWF4fEqSribVkx9EJyui
kqDunu5c0EMCefN7q1Ydor7cjZEwWdb2NZ4IO2HTQac2V4B+R+1YQBHF+kgHgT6S
r+9Ol62Tk5L6GqJLgzRGOPl0JvBuFLa6O1jyzYrowpWVty6w6C0cwO9JMQ==
=+RhY
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make ob-python.el support ":results pp" pretty print result
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Jack Kamm @ 2020-02-20 16:56 UTC (permalink / raw)
  To: numbchild, Org Mode

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?

Well, there is code in ob-python.el that uses the pprint module when
":results pp", but I must admit I've never used it and don't know
whether it is currently working. I'm also unsure there's a difference in
how session and non-session blocks deal with this.

I'll plan to test it out later this weekend or next week and see if I
can fix any issues. Or, if you're able, please feel free to submit a
patch (but please let me know if you plan to work on this, so we can
avoid duplicating effort).

Ideally, a patch for this would also include a unit test, to make sure
this doesn't break in future.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make ob-python.el support ":results pp" pretty print result
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Jack Kamm @ 2020-02-22 17:21 UTC (permalink / raw)
  To: numbchild, Org Mode

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-22 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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