From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin <jkitchin@andrew.cmu.edu> Subject: setting options to python interpreter for a code block Date: Wed, 11 Sep 2013 13:22:12 -0400 Message-ID: <CAJ51ETpJZdU5M4-fNmsOu5T2mqQkcSgYzV1xDNSk3=e3QmXy-A@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bdc9a5ca9ae4504e61edca7 Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org> Received: from eggs.gnu.org ([2001:4830:134:3::10]:50850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <johnrkitchin@gmail.com>) 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 <johnrkitchin@gmail.com>) 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 <johnrkitchin@gmail.com>) 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 <emacs-orgmode@gnu.org>; Wed, 11 Sep 2013 10:22:12 -0700 (PDT) List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>, <mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/archive/html/emacs-orgmode> List-Post: <mailto:emacs-orgmode@gnu.org> List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>, <mailto:emacs-orgmode-request@gnu.org?subject=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 <module> exec(content, ns_globals, ns_locals) File "<string>", line 10, in <module> 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 <div dir=3D"ltr"><div><div><div><div><div>Hi, <br></div><div>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.<b= r> <br>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.<br><br></div><div>Say test.py has this content<br><br>#+BEGIN_= SRC python <br> print 'hello'<br><br>print 4 + 6<br><br>import sys<br><br>print >= ;>sys.stderr, 'message to stderr'<br><br><br>raise Exception(= 9;baboom')<br>#+END_SRC<br><br></div><div>When I use the sandbox, I get= all the output on stdout like this.<br> </div><div><br></div><div>#+BEGIN_SRC sh<br>python -m sandbox < test.py<= br># or cat test.py | python -m sandbox <br>#+END_SRC<br><br>#+RESULTS:<br>= #+begin_example<br><br>----------------------------------------------------= ----------<br> hello<br>10<br><br><br>----------------------------------------------------= ----------<br>stderr:<br>message to stderr<br><br><br>---------------------= -----------------------------------------<br>Traceback (most recent call la= st):<br> =A0 File "/home/jkitchin/Dropbox/pycse/pycse/sandbox/sandbox.py",= line 16, in <module><br>=A0=A0=A0 exec(content, ns_globals, ns_local= s)<br>=A0 File "<string>", line 10, in <module><br>Ex= ception: baboom<br> <br><br>#+end_example<br></div><br><br></div>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.<br> </div></div><br></div>Is there some other way that I could do this? Thanks!= <br><div><div><br clear=3D"all"><div><div><div><div><div>John<br><br>------= -----------------------------<br>John Kitchin<br>Associate Professor<br>Doh= erty Hall A207F<br> Department of Chemical Engineering<br>Carnegie Mellon University<br>Pittsbu= rgh, PA 15213<br>412-268-7803<br><a href=3D"http://kitchingroup.cheme.cmu.e= du" target=3D"_blank">http://kitchingroup.cheme.cmu.edu</a><br><br></div> </div></div></div></div></div></div></div> --047d7bdc9a5ca9ae4504e61edca7--