* 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