From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: setting options to python interpreter for a code block Date: Wed, 11 Sep 2013 13:22:12 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bdc9a5ca9ae4504e61edca7 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJo7L-0000Nx-LB for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJo7K-0008Ik-63 for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 13:22:15 -0400 Received: from mail-pa0-x22a.google.com ([2607:f8b0:400e:c03::22a]:55569) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJo7J-0008IS-Pp for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 13:22:14 -0400 Received: by mail-pa0-f42.google.com with SMTP id lj1so9620539pab.1 for ; Wed, 11 Sep 2013 10:22:12 -0700 (PDT) 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: emacs-orgmode@gnu.org --047d7bdc9a5ca9ae4504e61edca7 Content-Type: text/plain; charset=ISO-8859-1 Hi, I am looking at a new strategy to capture stderr and exceptions in python code blocks. Right now exceptions are not captured in the output, and neither is stderr. I made a little sandbox module that captures stdout, stderr, and exceptions and then prints them all to stdout with some minor formatting. Here is an example. Say test.py has this content #+BEGIN_SRC python print 'hello' print 4 + 6 import sys print >>sys.stderr, 'message to stderr' raise Exception('baboom') #+END_SRC When I use the sandbox, I get all the output on stdout like this. #+BEGIN_SRC sh python -m sandbox < test.py # or cat test.py | python -m sandbox #+END_SRC #+RESULTS: #+begin_example -------------------------------------------------------------- hello 10 -------------------------------------------------------------- stderr: message to stderr -------------------------------------------------------------- Traceback (most recent call last): File "/home/jkitchin/Dropbox/pycse/pycse/sandbox/sandbox.py", line 16, in exec(content, ns_globals, ns_locals) File "", line 10, in Exception: baboom #+end_example So, I was wondering how to get this to happen in org-mode on a regular python block. I think it could work if I could define a custom interpreter for a particular block, e.g. python-sandbox that takes the codeblock on stdin. Is there some other way that I could do this? Thanks! John ----------------------------------- John Kitchin Associate Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu --047d7bdc9a5ca9ae4504e61edca7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
I am looking a= t a new strategy to capture stderr and exceptions in python code blocks. Ri= ght now exceptions are not captured in the output, and neither is stderr.
I made a little sandbox module that captures stdout, stderr, and except= ions and then prints them all to stdout with some minor formatting. Here is= an example.

Say test.py has this content

#+BEGIN_= SRC python
print 'hello'

print 4 + 6

import sys

print >= ;>sys.stderr, 'message to stderr'


raise Exception(= 9;baboom')
#+END_SRC

When I use the sandbox, I get= all the output on stdout like this.

#+BEGIN_SRC sh
python -m sandbox < test.py<= br># or cat test.py | python -m sandbox
#+END_SRC

#+RESULTS:
= #+begin_example

----------------------------------------------------= ----------
hello
10


----------------------------------------------------= ----------
stderr:
message to stderr


---------------------= -----------------------------------------
Traceback (most recent call la= st):
=A0 File "/home/jkitchin/Dropbox/pycse/pycse/sandbox/sandbox.py",= line 16, in <module>
=A0=A0=A0 exec(content, ns_globals, ns_local= s)
=A0 File "<string>", line 10, in <module>
Ex= ception: baboom


#+end_example


So, I was wondering how to get= this to happen in org-mode on a regular python block. I think it could wor= k if I could define a custom interpreter for a particular block, e.g. pytho= n-sandbox that takes the codeblock on stdin.

Is there some other way that I could do this? Thanks!=

John

------= -----------------------------
John Kitchin
Associate Professor
Doh= erty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsbu= rgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

--047d7bdc9a5ca9ae4504e61edca7--