From mboxrd@z Thu Jan  1 00:00:00 1970
From: Eric Schulte <schulte.eric@gmail.com>
Subject: Re: setting options to python interpreter for a code block
Date: Wed, 11 Sep 2013 12:17:10 -0600
Message-ID: <87bo3zw7dl.fsf@gmail.com>
References: <CAJ51ETpJZdU5M4-fNmsOu5T2mqQkcSgYzV1xDNSk3=e3QmXy-A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain
Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org>
Received: from eggs.gnu.org ([2001:4830:134:3::10]:60833)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <schulte.eric@gmail.com>) id 1VJoyR-0002I6-UT
	for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 14:17:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <schulte.eric@gmail.com>) id 1VJoyL-0007GS-KY
	for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 14:17:07 -0400
Received: from mail-pb0-x231.google.com ([2607:f8b0:400e:c01::231]:53444)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <schulte.eric@gmail.com>) id 1VJoyL-0007G9-DX
	for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 14:17:01 -0400
Received: by mail-pb0-f49.google.com with SMTP id xb4so9353700pbc.36
	for <emacs-orgmode@gnu.org>; Wed, 11 Sep 2013 11:17:00 -0700 (PDT)
In-Reply-To: <CAJ51ETpJZdU5M4-fNmsOu5T2mqQkcSgYzV1xDNSk3=e3QmXy-A@mail.gmail.com>
	(John Kitchin's message of "Wed, 11 Sep 2013 13:22:12 -0400")
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: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: emacs-orgmode@gnu.org

You could try setting org-babel-python-command to "python -m sandbox".

If that doesn't work we could add a cmdline header argument to python
code blocks pretty easily.

Cheers,

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> 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

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D