From mboxrd@z Thu Jan 1 00:00:00 1970 From: R C Subject: ob-python.el: questions about output Date: Sun, 23 Feb 2020 11:43:41 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000082a788059f4526f3" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:59891) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5z2X-0003t7-SY for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 16:43:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5z2W-0005Z7-LB for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 16:43:53 -0500 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:37952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j5z2W-0005Yu-FN for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 16:43:52 -0500 Received: by mail-qt1-x830.google.com with SMTP id i23so5334327qtr.5 for ; Sun, 23 Feb 2020 13:43:52 -0800 (PST) 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: emacs-orgmode@gnu.org --00000000000082a788059f4526f3 Content-Type: text/plain; charset="UTF-8" The approach proposed for graphical output at https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html is ```` #+begin_src python :results file import matplotlib, numpy matplotlib.use('Agg') import matplotlib.pyplot as plt fig=plt.figure(figsize=(4,2)) x=numpy.linspace(-15,15) plt.plot(numpy.sin(x)/x) fig.tight_layout() plt.savefig('images/python-matplot-fig.png') return 'images/python-matplot-fig.png' # return filename to org-mode #+end_src ```` and to use :results output for displaying stdout. 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? 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. Thanks, RC --00000000000082a788059f4526f3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

The approach proposed for gra= phical output at https://orgmode.org/worg/org-contrib/babel/langua= ges/ob-doc-python.html is

````
#+begin_src python :results file
import matplotlib, numpy
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig=3Dplt.figure(figsize=3D(4,2))
x=3Dnumpy.linspace(-15,15)
plt.plot(numpy.sin(x)/x)
fig.tight_layout()
plt.savefig('images/python-matplot-fig.png')
return 'images/python-matplot-fig.png' # return filename to org-mod=
e
#+end_src
````
and to use :results outpu=
t for displaying stdout.
1. Is it possible to have both= types of output displayed from a single src block to avoid having to dupli= cate the src block, using :exports results for one and :exports both for th= e other?
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.

Thanks,
RC<= /div>
--00000000000082a788059f4526f3-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: Re: ob-python.el: questions about output Date: Sun, 23 Feb 2020 20:52:08 -0800 Message-ID: <87eeuky4cn.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:36038) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j65k9-0006mu-G6 for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 23:53:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j65k8-0004F2-Gv for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 23:53:21 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:37356) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j65k8-0004B7-9K for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 23:53:20 -0500 Received: by mail-pj1-x1030.google.com with SMTP id m13so3615095pjb.2 for ; Sun, 23 Feb 2020 20:53:20 -0800 (PST) In-Reply-To: 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: R C , emacs-orgmode@gnu.org 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? From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: Re: ob-python.el: questions about output Date: Sun, 23 Feb 2020 20:53:04 -0800 Message-ID: <87blpoy4b3.fsf@gmail.com> References: <87eeuky4cn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:36079) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j65l3-0007fP-8S for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 23:54:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j65l2-0005DQ-Fz for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 23:54:17 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:39300) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j65l2-0005Ca-Av for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 23:54:16 -0500 Received: by mail-pl1-x629.google.com with SMTP id g6so3533052plp.6 for ; Sun, 23 Feb 2020 20:54:16 -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: R C , emacs-orgmode@gnu.org Sorry, my email had a typo: > #+begin_src python :session session1 :results output > x > #+end_src That should be ":results value". 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-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Fraga, Eric" Subject: Re: ob-python.el: questions about output Date: Mon, 24 Feb 2020 13:42:08 +0000 Message-ID: <87sgj06r0y.fsf@ucl.ac.uk> References: <87eeuky4cn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:42800) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Dzw-0005e3-V7 for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 08:42:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Dzv-0005Eu-Vk for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 08:42:12 -0500 Received: from mail-am6eur05on2107.outbound.protection.outlook.com ([40.107.22.107]:31713 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Dzv-0005Eb-IU for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 08:42:11 -0500 In-Reply-To: (R. C.'s message of "Mon, 24 Feb 2020 02:13:10 -0500") Content-Language: en-US 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: R C Cc: "emacs-orgmode@gnu.org" On Monday, 24 Feb 2020 at 02:13, R C wrote: > When exported I would like the line: return 'img/ex1.png' not to be > included in the listing of the src block. I don't think this is currently possible in the sense you want. You could use :noweb where you have one src block referring to others and only output the code for the main body. E.g. something along the lines of #+name: mainblock #+begin_src python :results file :noweb yes 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 are {x}') x_ =3D np.linspace(np.min(x), np.max(x), 100) #+end_src #+name: full #+begin_src python :results file :noweb yes import numpy as np import matplotlib.pyplot as plt <> plt.plot(x_, f(x_)) plt.plot(x, f(x), marker=3D'o') plt.savefig('img/ex1.png') return 'img/ex1.png' #+end_src Longer term, better would be an implementation of :prologue and :epilogue options for python src blocks like we have for Maxima. It would probably make sense to provide these options for most if not all src blocks? --=20 : Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-354-g9d5880 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: Re: ob-python.el: questions about output Date: Mon, 24 Feb 2020 08:17:08 -0800 Message-ID: <878sksx8mz.fsf@gmail.com> References: <87eeuky4cn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:39345) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6GR3-0002ue-R5 for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:18:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6GR2-0002VO-P6 for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:18:21 -0500 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:42122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6GR2-0002Ux-K0 for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:18:20 -0500 Received: by mail-pf1-x42a.google.com with SMTP id 4so5594373pfz.9 for ; Mon, 24 Feb 2020 08:18:20 -0800 (PST) In-Reply-To: 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: R C Cc: emacs-orgmode@gnu.org Hi RC, R C writes: > My python src blocks often have both graphical output as well as the > results of some numerical calculation displayed using print statements. > > 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. The external ob-jupyter [0] accomplishes what you want: 1. It can return multiple types of output, e.g. print statements and plots. 2. It doesn't require the "return" statement. It's main limitations are: 1. It requires jupyter. 2. It requires using session blocks. I'd recommend checking it out. It has excellent Python support. If you prefer a native solution, I think the options are: 1. noweb (as Eric mentioned). Then you only need to write the code once, but note that it will be executed twice. 2. Using multiple session blocks to return output and value separately. Since they use the same state, you would only need to execute the code once. 3. Possibly, you could insert the link to the image separately, create a named reference to it, and pass it to the Python block via ":var", which would create at an image at that link. Then use ":results output" to capture the print statements. I'm not 100% sure if this will work. [0] https://github.com/dzop/emacs-jupyter From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: Re: ob-python.el: questions about output Date: Mon, 24 Feb 2020 08:18:33 -0800 Message-ID: <875zfwx8km.fsf@gmail.com> References: <87eeuky4cn.fsf@gmail.com> <87sgj06r0y.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:39599) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6GST-0004YT-8T for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:19:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6GSP-0002rq-Es for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:19:49 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:32797) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6GSP-0002re-9B for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:19:45 -0500 Received: by mail-pf1-x436.google.com with SMTP id n7so5621930pfn.0 for ; Mon, 24 Feb 2020 08:19:45 -0800 (PST) In-Reply-To: <87sgj06r0y.fsf@ucl.ac.uk> 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: "Fraga, Eric" , R C Cc: "emacs-orgmode@gnu.org" Hi Eric, "Fraga, Eric" writes: > Longer term, better would be an implementation of :prologue and > :epilogue options for python src blocks like we have for Maxima. It > would probably make sense to provide these options for most if not all > src blocks? This sounds interesting. Do you know of any documentation or examples for :prologue and :epilogue? I checked the Worg page for ob-maxima, but it didn't mention these header arguments. From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Fraga, Eric" Subject: Re: ob-python.el: questions about output Date: Mon, 24 Feb 2020 16:40:16 +0000 Message-ID: <87d0a4547v.fsf@ucl.ac.uk> References: <87eeuky4cn.fsf@gmail.com> <878sksx8mz.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43225) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6GmK-0006wl-Uj for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:40:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6GmJ-0001cf-Lc for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:40:20 -0500 Received: from mail-eopbgr80114.outbound.protection.outlook.com ([40.107.8.114]:63205 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6GmJ-0001bx-CB for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:40:19 -0500 In-Reply-To: <878sksx8mz.fsf@gmail.com> (Jack Kamm's message of "Mon, 24 Feb 2020 08:17:08 -0800") Content-Language: en-US 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: R C , "emacs-orgmode@gnu.org" On Monday, 24 Feb 2020 at 08:17, Jack Kamm wrote: > 1. noweb (as Eric mentioned). Then you only need to write the code > once, but note that it will be executed twice. Doesn't need to execute twice: maybe add ":eval no" to the first block, the one that will be included in the other one? --=20 : Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-354-g9d5880 From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Fraga, Eric" Subject: Re: ob-python.el: questions about output Date: Mon, 24 Feb 2020 16:49:07 +0000 Message-ID: <878sks53sv.fsf@ucl.ac.uk> References: <87eeuky4cn.fsf@gmail.com> <87sgj06r0y.fsf@ucl.ac.uk> <875zfwx8km.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:44328) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Gut-0002Oo-PE for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:49:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Gus-0005i6-Nq for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:49:11 -0500 Received: from mail-eopbgr80119.outbound.protection.outlook.com ([40.107.8.119]:44611 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Gus-0005hd-B4 for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 11:49:10 -0500 In-Reply-To: <875zfwx8km.fsf@gmail.com> (Jack Kamm's message of "Mon, 24 Feb 2020 08:18:33 -0800") Content-Language: en-US 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: R C , "emacs-orgmode@gnu.org" On Monday, 24 Feb 2020 at 08:18, Jack Kamm wrote: > This sounds interesting. Do you know of any documentation or examples > for :prologue and :epilogue? I checked the Worg page for ob-maxima, but > it didn't mention these header arguments. I don't know of any documentation. They basically simply provide strings that are included before and after the text within the src block before evaluation but are not exported in a code listing. I can give you an example of how I use these with maxima: #+header: :prologue "fpprintprec: 2; linel: 50;" #+header: :epilogue "print(solution);" #+begin_src maxima :exports both :results output :cache yes solution: exp(1.0); #+end_src which sets the printing precision for numbers to 2 and the line length to 50 and prints out the contents of the solution variable at the end. These are details that are not important for display; I use these settings all the time for my lecture slides. The above example gives the following when exported to ascii: ,---- | solution: exp(1.0); `---- ,---- | 2.7=20 `---- so the slides can concentrate on the material that is important. Adding such to ob-python etc. should not be difficult. --=20 : Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-354-g9d5880 From mboxrd@z Thu Jan 1 00:00:00 1970 From: R C Subject: Re: ob-python.el: questions about output Date: Wed, 26 Feb 2020 23:29:03 -0500 Message-ID: References: <87eeuky4cn.fsf@gmail.com> <878sksx8mz.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000af19d2059f8b5a52" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:49645) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7FTo-0002Vm-Ps for emacs-orgmode@gnu.org; Thu, 27 Feb 2020 04:29:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7FTn-0008Lk-FG for emacs-orgmode@gnu.org; Thu, 27 Feb 2020 04:29:16 -0500 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]:43969) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j7FTn-0008Kg-8q for emacs-orgmode@gnu.org; Thu, 27 Feb 2020 04:29:15 -0500 Received: by mail-qt1-x829.google.com with SMTP id g21so1746353qtq.10 for ; Thu, 27 Feb 2020 01:29:14 -0800 (PST) In-Reply-To: <878sksx8mz.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 --000000000000af19d2059f8b5a52 Content-Type: text/plain; charset="UTF-8" Hi Jack, Thanks for your suggestion to use ob-jupyter. That gives me the stdout and graphical output in separate results blocks as I wanted, and no return statement is needed. I don't know if there are any side-effects to using multiple sessions in a single org file, but so far it seems to work quite well. On Mon, Feb 24, 2020 at 11:18 AM Jack Kamm wrote: > Hi RC, > > R C writes: > > > My python src blocks often have both graphical output as well as the > > results of some numerical calculation displayed using print statements. > > > > 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. > > The external ob-jupyter [0] accomplishes what you want: > > 1. It can return multiple types of output, e.g. print statements and plots. > 2. It doesn't require the "return" statement. > > It's main limitations are: > 1. It requires jupyter. > 2. It requires using session blocks. > > I'd recommend checking it out. It has excellent Python support. > > If you prefer a native solution, I think the options are: > > 1. noweb (as Eric mentioned). Then you only need to write the code > once, but note that it will be executed twice. > > 2. Using multiple session blocks to return output and value > separately. Since they use the same state, you would only need to > execute the code once. > > 3. Possibly, you could insert the link to the image separately, create a > named reference to it, and pass it to the Python block via ":var", which > would create at an image at that link. Then use ":results output" to > capture the print statements. I'm not 100% sure if this will work. > > [0] https://github.com/dzop/emacs-jupyter > -- Regards, RC --000000000000af19d2059f8b5a52 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Jack,
Thanks for your suggestion to use = ob-jupyter. That gives me the stdout and graphical output in separate resul= ts blocks as I wanted, and no return statement is needed. I don't know = if there are any side-effects to using multiple sessions in a single org fi= le, but so far it seems to work quite well.

On Mon, Feb 24, 2020= at 11:18 AM Jack Kamm <jackkamm@g= mail.com> wrote:
Hi RC,

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

> My python src blocks often have both graphical output as well as the > results of some numerical calculation displayed using print statements= .
>
> 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.=

The external ob-jupyter [0] accomplishes what you want:

1. It can return multiple types of output, e.g. print statements and plots.=
2. It doesn't require the "return" statement.

It's main limitations are:
1. It requires jupyter.
2. It requires using session blocks.

I'd recommend checking it out. It has excellent Python support.

If you prefer a native solution, I think the options are:

1. noweb (as Eric mentioned). Then you only need to write the code
once, but note that it will be executed twice.

2. Using multiple session blocks to return output and value
separately. Since they use the same state, you would only need to
execute the code once.

3. Possibly, you could insert the link to the image separately, create a named reference to it, and pass it to the Python block via ":var"= , which
would create at an image at that link. Then use ":results output"= to
capture the print statements. I'm not 100% sure if this will work.

[0] https://github.com/dzop/emacs-jupyter


--
Regards,
RC
--000000000000af19d2059f8b5a52--