emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [PATCH] ob-python: support header argument `:results file graphics'


From: Ihor Radchenko
Subject: Re: [PATCH] ob-python: support header argument `:results file graphics'
Date: Tue, 04 Jul 2023 11:29:20 +0000

[ CCing ob-python maintainer. ]

Liu Hui <liuhui1610@gmail.com> writes:

>> May you elaborate?
>>
>> #+begin_src python :results file
>> implies that the result of execution is file _contents_.
>
> It is consistent with current behavior, e.g. `:results file' is used
> to produce graphics file
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html

WORG documentation is not accurate here.

More precisely,

#+name: some-name
#+begin_src python :results file :file-ext txt

will interpret results as file contents of "some-name.txt".

If the block has :file parameter _or_ :file-exp parameter and #+name,
the results of evaluation are inserted into a file. Otherwise, results
of evaluation are interpreted as file name--*undocumented*.

That said, your patch should still work fine even with these
considerations. But we may need to sort out this undocumented behaviour.
Probably, an error like in `org-babel-graphical-output-file' should be
thrown by `org-babel-generate-file-param'.

> Any src blocks worked in the past still work with this patch, without
> any adjustments. The patch only makes the following src block, which
> cannot produce `test.png' in the past, can produce `test.png'.
>
> #+begin_src python :file "test.png" :results graphics file
> import matplotlib.pyplot as plt
> plt.plot([1,2,3,4,5])
> #+end_src

Right.

What about

#+begin_src python :file "test.png" :results graphics file
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5])
plt.savefig('test.png')
plt.plot([5,4,3,2,1])
plt.show()
#+end_src

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

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