From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: python :session and org_babel_python_eoe Date: Thu, 10 Feb 2011 18:45:05 +0000 Message-ID: References: <20110210174619.202459f9@bill> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=48639 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnbVx-0000GR-OB for emacs-orgmode@gnu.org; Thu, 10 Feb 2011 13:45:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PnbVw-0006Qm-G3 for emacs-orgmode@gnu.org; Thu, 10 Feb 2011 13:45:13 -0500 Received: from mail-wy0-f169.google.com ([74.125.82.169]:41855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PnbVw-0006QX-5k for emacs-orgmode@gnu.org; Thu, 10 Feb 2011 13:45:12 -0500 Received: by wyj26 with SMTP id 26so1717529wyj.0 for ; Thu, 10 Feb 2011 10:45:11 -0800 (PST) In-Reply-To: <20110210174619.202459f9@bill> (Myles English's message of "Thu, 10 Feb 2011 17:46:19 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Myles English Cc: emacs-orgmode@gnu.org Myles English writes: > Hello, > > Is this behaviour expected?: > > #+begin_src python :session > import sys > #+end_src > > #+results: > > But in the python interpreter there is this: > > """ >>>> import sys > > > open('/home/myles/tmp/scratch/python-4938gzQ', 'w').write(str(_)) > > > 'org_babel_python_eoe' >>>> >>> >>> Traceback (most recent call last): > File "", line 1, in > NameError: name '_' is not defined >>>> >>> >>> 'org_babel_python_eoe' Hi Myles, Firstly, I'm aware that python sessions are a little rough round the edges in places. I've recently started to use them quite a bit and would like to improve them, so any reports of problems you encounter will be appreciated. Yes, this is expected, although we could do without it. Since you did not specify :results, you are in the default "value" mode, which attempts to return to the org buffer the last value computed, using the special variable _. However, _ does not yet exist as you haven't computed anything. You could do #+begin_src python :session import sys None #+end_src Or you could use :results output here, which will result in a cleaner session buffer in this particular case. I wonder whether it would make sense to support :results nil, meaning "I know in advance that I want the result to be nil, so don't try to retrieve any results for me". That may be useful in order to execute a src block that would return an extremely large result -- one which you really don't want emacs to try to deal with at all. Perhaps the value of :results could even be allowed to be a lisp form in general, in addition to "output" and "value" and "silent". The open(...).write(str(_)) is org-babel internals -- that's how Org gets the value out of python and back to the org buffer. Ideally, it would not be exposed to the user -- but so far R is the only babel language where we've hidden it. So the solution in terms of babel development could be 1. Test for the existence of _ before attempting to write it. Perhaps using locals().get('_') is None and 2. Don't echo that stuff to the python session buffer Also, the 'org_babel_python_eoe', shouldn't really be there -- it only makes sense in :results output mode. Dan >>>> > """ > > The sys module did indeed import correctly though. And that file > (/home/myles/tmp/scratch/python-4938gzQ) is empty. > > Versions: > - Python 2.7.1 (r271:86832, Jan 6 2011, 11:45:30) [GCC 4.5.2] on > linux2 > - orgmode from git 7473e3 Wed Feb 9 17:30 > - GNU Emacs 23.2.1(x86_64-unknown-linux-gnu) > > It looks related to the issue, described as being fixed, in this > thread: ("org-babel :session breaks returning things with python?") > http://news.gmane.org/find-root.php?message_id=%3c871v669swp.fsf%40gmail.com%3e > > Thanks, > > Myles > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode