From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Suppressing interpeter output in code blocks Date: Thu, 06 Jun 2013 12:28:43 -0600 Message-ID: <87ip1rhz50.fsf@gmail.com> References: <51AF9934.6000009@raingods.net> <87a9n36x9q.fsf@gmail.com> <51B0D02F.4040007@raingods.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkfAg-0005oh-FT for emacs-orgmode@gnu.org; Thu, 06 Jun 2013 14:44:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkewH-0000Yp-R7 for emacs-orgmode@gnu.org; Thu, 06 Jun 2013 14:29:47 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:60458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkewH-0000YM-Ik for emacs-orgmode@gnu.org; Thu, 06 Jun 2013 14:29:33 -0400 Received: by mail-pd0-f182.google.com with SMTP id g10so3718482pdj.13 for ; Thu, 06 Jun 2013 11:29:32 -0700 (PDT) In-Reply-To: <51B0D02F.4040007@raingods.net> (Michael Steeves's message of "Thu, 06 Jun 2013 14:08:47 -0400") 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.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Michael Steeves Cc: Orgmode Mailing List , Eric Schulte --=-=-= Content-Type: text/plain Michael Steeves writes: > On 6/6/13 12:04 PM, Eric Schulte wrote: >> Michael Steeves writes: >>> Is there any way to suppress all the extra text, and just get the >>> "Hello, world." string as my output? >>> >> >> #+begin_src python :session testing >> a = 1 >> b = 2 >> c = a + b >> "Hello, world." >> #+end_src >> >> #+RESULTS: >> : Hello, world. > > Thanks for the reply. Unfortunately I need to set :results to output, > since I'm working with a doc where I'm working through a python script, > and want to run a section, get some output and write some additional > text, then move on to the next block (and all within a session, since > block 2 depends on things from block 1, and so on. > > I put together a more descriptive example, but interestingly enough I'm > now getting some inconsistent output when I evaluate the source blocks. > > #+BEGIN_SRC python :session testing :results output > print "Hello, World." > print "This is a test." > #+END_SRC > > #+RESULTS: > : Hello, World. > : This is a test. > > #+BEGIN_SRC python :session testing :results output > a = 1; b = 2 > print "A is "+str(a) > print "B is "+str(b) > #+END_SRC > > #+RESULTS: > : > : A is 1 > : B is 2 > > #+BEGIN_SRC python :session testing :results output > c = a + b > print "C is "+str(c) > print "Now we're done." > #+END_SRC > > #+RESULTS: > : > : C is 3 > : Now we're done. > > #+BEGIN_SRC python :session testing :results output > y = 3 > z = 4 > print "Y is "+str(y) > print "Z is "+str(z) > #+END_SRC > > #+RESULTS: > : > : >>> Y is 3 > : Z is 4 > > I don't understand why the last chunk provides different output than the > second -- the only real difference is that I put the assignments on one > line (seperated with a semicolon) in the second, and on individual lines > in the last. > The cleaning of prompts is a best effort based on things like the prompt regexp variable in the python session comint buffer. As it interacts with an external process it can be somewhat noisy, seemingly especially so with python sessions. The attached version of your example file uses a simple post processor to automatically clean up anything that looks like python session cruft after each code block execution. --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=python-session.org #+Property: post py-session-clean(*this*) #+BEGIN_SRC python :session testing :results output print "Hello, World." print "This is a test." #+END_SRC #+RESULTS: : Hello, World. : This is a test. #+BEGIN_SRC python :session testing :results output a = 1; b = 2; print "A is "+str(a) print "B is "+str(b) #+END_SRC #+RESULTS: : A is 1 : B is 2 #+BEGIN_SRC python :session testing :results output c = a + b print "C is "+str(c) print "Now we're done." #+END_SRC #+RESULTS: : C is 3 : Now we're done. #+BEGIN_SRC python :session testing :results output y = 3 z = 4 print "Y is "+str(y) print "Z is "+str(z) #+END_SRC #+RESULTS: : Y is 3 : Z is 4 * COMMENT Helper Function #+name: py-session-clean #+begin_src sh :var data="" :results output :post '() echo "$data"|sed '/^$/d;s/^>\+ //g' #+end_src --=-=-= Content-Type: text/plain Hope this helps, > > > -Mike -- Eric Schulte http://cs.unm.edu/~eschulte --=-=-=--