From mboxrd@z Thu Jan 1 00:00:00 1970 From: R C Subject: Re: ob-python.el: questions about output Date: Mon, 24 Feb 2020 02:13:10 -0500 Message-ID: References: <87eeuky4cn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000005076059f514c31" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:58620) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Cby-0007Ee-4C for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 07:13:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Cbw-0007gA-PD for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 07:13:22 -0500 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:44908) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6Cbw-0007ft-JH for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 07:13:20 -0500 Received: by mail-qt1-x831.google.com with SMTP id j23so6350169qtr.11 for ; Mon, 24 Feb 2020 04:13:20 -0800 (PST) In-Reply-To: <87eeuky4cn.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: Jack Kamm Cc: emacs-orgmode@gnu.org --000000000000005076059f514c31 Content-Type: text/plain; charset="UTF-8" Hi Jack, Thanks for your response. Sorry for not being clearer. My python src blocks often have both graphical output as well as the results of some numerical calculation displayed using print statements. #+begin_src python :results file import numpy as np import matplotlib.pyplot as plt def f(x): return np.polyval(a, x) a = [1, -4, 4.5, -1.5] x = np.roots(a) print(f'Roots of the polynomial are {x}') x_ = np.linspace(np.min(x), np.max(x), 100) plt.plot(x_, f(x_)) plt.plot(x, f(x), marker='o') plt.savefig('img/ex1.png') return 'img/ex1.png' #+end_src Executing this results in #+RESULTS: [[file:img/ex1.png]] When exported I would like the line: return 'img/ex1.png' not to be included in the listing of the src block. Also, the output of the print statement is not displayed in this case. It seems that the display of the results of the print statement: print(f'Roots of the polynomial are {x}') , would require execution of a duplicate src block without the return statement in the last line, and with ':results output' replacing ':results file' which gives: #+RESULTS: : Roots of the polynomial are [2.3660254 1. 0.6339746] I would have liked to avoid the duplication if possible. Thanks, RC On Sun, Feb 23, 2020 at 11:53 PM Jack Kamm wrote: > Hi RC, > > R C writes: > > > 1. Is it possible to have both types of output displayed from a single > src > > block to avoid having to duplicate the src block, using :exports results > > for one and :exports both for the other? > > No, there's no option to output both ":results output" and ":results > value". > > If you want both output and value results, and want to avoid executing > the same code twice, you could consider using a pair of ":session" > blocks, for example: > > #+begin_src python :session session1 :results output > print("Block that does some computations") > x = 1+1 > #+end_src > > #+begin_src python :session session1 :results output > x > #+end_src > > > 2. Is there an option to suppress export of the the last line of the src > > block which is specific to the ob-python implementation. > > I'm not sure what you mean by this, could you give an example of what > the observed and desired behaviors are? > --000000000000005076059f514c31 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Jack,
Thanks for yo= ur response. Sorry for not being clearer.

My python src blocks often have both graphical output as well as the=20 results of some numerical calculation displayed using print statements.
#+begin_src python :results file
import numpy as np
import ma= tplotlib.pyplot as plt
def f(x): return np.polyval(a, x)
a =3D [1, -4= , 4.5, -1.5]
x =3D np.roots(a)
print(f'Roots of the polynomial ar= e {x}')
x_ =3D np.linspace(np.min(x), np.max(x), 100)
plt.plot(x_= , f(x_))
plt.plot(x, f(x), marker=3D'o')
plt.savefig('img= /ex1.png')
return 'img/ex1.png'
#+end_src
<= br>
Executing this results in

#+RES= ULTS:
[[file:img/ex1.png]]

When exported I woul= d like the line: return 'img/ex1.png' not to be included in the lis= ting of the src block.

Also, the output of the print statement is not displayed in this case. It=20 seems that the display of the results of the print statement:=20 print(f'Roots of the polynomial are {x}') , would require=C2=A0 exe= cution of a duplicate src block without the return statement=C2=A0 in the last line, a= nd with ':results output' replacing ':results file'=C2=A0 whi= ch gives:

#+RESULTS:
: Roots of the polynomial = are [2.3660254 1. =C2=A0 =C2=A0 =C2=A0 =C2=A00.6339746]

<= /div>
I would have liked to avoid the duplication if possible.

Thanks,
RC

On Sun, Feb 23, 2020 at 11:53 PM= Jack Kamm <jackkamm@gmail.com= > wrote:
Hi R= C,

R C <recifx@gmail.= com> writes:

> 1. Is it possible to have both types of output displayed from a single= src
> block to avoid having to duplicate the src block, using :exports resul= ts
> for one and :exports both for the other?

No, there's no option to output both ":results output" and &q= uot;:results value".

If you want both output and value results, and want to avoid executing
the same code twice, you could consider using a pair of ":session"= ;
blocks, for example:

#+begin_src python :session session1 :results output
print("Block that does some computations")
x =3D 1+1
#+end_src

#+begin_src python :session session1 :results output
x
#+end_src

> 2. Is there an option to suppress export of the the last line of the s= rc
> block which is specific to the ob-python implementation.

I'm not sure what you mean by this, could you give an example of what the observed and desired behaviors are?

--000000000000005076059f514c31--