Re: Make ob-python.el support ":results pp" pretty print result
Hi stardiviner, stardiviner 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__': , > '__cached__': None, > '__doc__': None, > '__file__': '', > '__loader__': , > '__name__': '__main__', > '__package__': None, > '__spec__': None, > 'main': , > 'pprint': } > #+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__ | : | | __spec__ | > : | hline | __annotations__ | : | nil | __builtins__ | : | | (built-in) | > | __file__ | : | | __cached__ | : | hline | main | : > | | 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__': , '__spec__': None, > '__annotations__': {}, '__builtins__': , > '__file__': '', '__cached__': None} I also tested this on ":session" blocks and the results were the same.
Re: Make ob-python.el support ":results pp" pretty print result
Hi stardiviner, stardiviner 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.
Make ob-python.el support ":results pp" pretty print result
-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-