emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Suppressing interpeter output in code blocks
@ 2013-06-05 20:01 Michael Steeves
  2013-06-06 16:04 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Steeves @ 2013-06-05 20:01 UTC (permalink / raw)
  To: Orgmode Mailing List

Apologies if this is documented somehere, but I haven't been having much
luck in trying to find the answer to this.

If I have an org doc with some python code in it

#+begin_src python :session testing :results output
a = 1
b = 2
c = a + b
print "Hello, world."
#+end_src

when I evaluate the block, the output is

#+RESULTS:
: Python 2.7.5 (default, May 19 2013, 13:26:46)
: [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))]
on darwin
: Type "help", "copyright", "credits" or "license" for more information.
: >>> >>> Hello, world.

Is there any way to suppress all the extra text, and just get the
"Hello, world." string as my output?




-Mike
-- 
Michael Steeves (steeves@raingods.net)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Suppressing interpeter output in code blocks
  2013-06-05 20:01 Suppressing interpeter output in code blocks Michael Steeves
@ 2013-06-06 16:04 ` Eric Schulte
  2013-06-06 18:08   ` Michael Steeves
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2013-06-06 16:04 UTC (permalink / raw)
  To: Michael Steeves; +Cc: Orgmode Mailing List

Michael Steeves <steeves@raingods.net> writes:

> Apologies if this is documented somehere, but I haven't been having much
> luck in trying to find the answer to this.
>
> If I have an org doc with some python code in it
>
> #+begin_src python :session testing :results output
> a = 1
> b = 2
> c = a + b
> print "Hello, world."
> #+end_src
>
> when I evaluate the block, the output is
>
> #+RESULTS:
> : Python 2.7.5 (default, May 19 2013, 13:26:46)
> : [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))]
> on darwin
> : Type "help", "copyright", "credits" or "license" for more information.
> : >>> >>> Hello, world.
>
> 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.

Best,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Suppressing interpeter output in code blocks
  2013-06-06 16:04 ` Eric Schulte
@ 2013-06-06 18:08   ` Michael Steeves
  2013-06-06 18:28     ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Steeves @ 2013-06-06 18:08 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Orgmode Mailing List

On 6/6/13 12:04 PM, Eric Schulte wrote:
> Michael Steeves <steeves@raingods.net> 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.


-Mike
-- 
Michael Steeves (steeves@raingods.net)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Suppressing interpeter output in code blocks
  2013-06-06 18:08   ` Michael Steeves
@ 2013-06-06 18:28     ` Eric Schulte
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2013-06-06 18:28 UTC (permalink / raw)
  To: Michael Steeves; +Cc: Orgmode Mailing List, Eric Schulte

[-- Attachment #1: Type: text/plain, Size: 2249 bytes --]

Michael Steeves <steeves@raingods.net> writes:

> On 6/6/13 12:04 PM, Eric Schulte wrote:
>> Michael Steeves <steeves@raingods.net> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: python-session.org --]
[-- Type: text/x-org, Size: 805 bytes --]

#+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

[-- Attachment #3: Type: text/plain, Size: 77 bytes --]


Hope this helps,

>
>
> -Mike

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-06 18:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-05 20:01 Suppressing interpeter output in code blocks Michael Steeves
2013-06-06 16:04 ` Eric Schulte
2013-06-06 18:08   ` Michael Steeves
2013-06-06 18:28     ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).