emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Make ob-python.el support ":results pp" pretty print result


From: Jack Kamm
Subject: Re: Make ob-python.el support ":results pp" pretty print result
Date: Sat, 22 Feb 2020 09:21:12 -0800

Hi stardiviner,

stardiviner <address@hidden> 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.



reply via email to

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