From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: python :session issues Date: Wed, 6 Feb 2013 10:17:37 -0500 Message-ID: References: <87r4ktiilv.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d040891519252fe04d50fd3fd Return-path: Received: from eggs.gnu.org ([208.118.235.92]:46443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36ks-00050p-HS for emacs-orgmode@gnu.org; Wed, 06 Feb 2013 10:17:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U36kl-0003xy-Az for emacs-orgmode@gnu.org; Wed, 06 Feb 2013 10:17:46 -0500 Received: from mail-lb0-f176.google.com ([209.85.217.176]:63002) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36kk-0003wU-V2 for emacs-orgmode@gnu.org; Wed, 06 Feb 2013 10:17:39 -0500 Received: by mail-lb0-f176.google.com with SMTP id s4so1259400lbc.7 for ; Wed, 06 Feb 2013 07:17:37 -0800 (PST) In-Reply-To: <87r4ktiilv.fsf@gmail.com> 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: Myles English Cc: emacs-orgmode@gnu.org --f46d040891519252fe04d50fd3fd Content-Type: text/plain; charset=ISO-8859-1 Thanks for the -Q reminder. I get the same output if I run with emacs -Q (although I do have to add :results output to each block. I had that set as a default in my init files). I had the problem described in the footnote you listed, and that is why I am using python-mode 5.2, which doesn't have that issue. 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 On Wed, Feb 6, 2013 at 10:10 AM, Myles English wrote: > > Hi John, > > John Kitchin writes: > > > I have been trying to use the :session feature of babel for python code > > blocks. I have noticed a few things that might be areas for > > improvement. Some issues are related to what I think might be a need for > > sanitizing the code blocks and the output. > > > > I am using (insert (org-version)) 7.9.3a > > I am using python-mode 5.2 (more modern versions do not work with > > :session for me) > > > > The first small detail is illustrated here: > > > > #+BEGIN_SRC python :session > > a = 5 > > > > b = 6 > > > > print a + b > > #+END_SRC > > > > #+RESULTS: > > : > > : >>> >>> >>> 11 > > > > In the output, there are three sets of >>>, due to the two empty > > lines. Compare this to > > > > #+BEGIN_SRC python :session > > a = 5 > > b = 6 > > print a + b > > #+END_SRC > > > > #+RESULTS: > > : > > : >>> 11 > > > > I think it would be nice to sanitize the python code block sent to the > > interpreter to eliminate the empty lines, and avoid the multiple >>> in > > output. It would also be nice to have an option to not print those at > > all. > > > > The second issue is related. The following code does not work for me in > > :session, but it works fine as a standalone block. The issue is related > > to the presence of an empty line in the function definition. I like > > whitespace like this in functions sometimes for readability. > > > > #+BEGIN_SRC python :session > > def func(x): > > 'doc string' > > > > return x**2 > > > > print func(2) > > #+END_SRC > > > > #+RESULTS: > > : > > : ... >>> File "", line 1 > > : return x**2 > > : ^ > > : IndentationError: unexpected indent > > : >>> None > > > > Removing the blank line works fine, but still has some non-pretty > > output. > > > > #+BEGIN_SRC python :session > > def func(x): > > 'doc string' > > return x**2 > > > > print func(2) > > #+END_SRC > > > > #+RESULTS: > > : > > : ... ... >>> 4 > > > > One of the ellipsis is due to the doc string. > > #+BEGIN_SRC python :session > > def func(x): > > return x**2 > > > > print func(2) > > #+END_SRC > > > > #+RESULTS: > > : > > : ... >>> 4 > > > > Interestingly, this did not work, because there is no empty line after > > the function definition. So, sanitizing could be tricky. > > > > #+BEGIN_SRC python :session > > def func(x): > > 'doc string' > > return x**2 > > print func(2) > > #+END_SRC > > > > #+RESULTS: > > : > > : ... ... File "", line 4 > > : print func(2) > > : ^ > > : SyntaxError: invalid syntax > > > > I think if there was a way to strip all the empty lines from the input, > > it would go a long way to making the output look like what I think most > > people would expect and want. > > > > Anyway, those are the examples I wanted to highlight in this > > post. > > > > > > 1. Do you see similar behavior, or is this a feature of my setup? > > I haven't tried your examples (no time) but you would be able to tell if > it was a feature of your setup by making a minimum working example and > starting emacs with 'emacs -Q'. If you see the thread in the footnote > it contains such an example. > > > 2. Is there any interest in sanitizing the input and output of a > > python :session to get prettier output? if so, Any hints on where to > > start with that? > > I had some problems recently with :session, there was a short > discussion[1], > and last I heard the maintainer of python-mode.el is looking into it. > > Myles > > Footnotes: > [1] > https://lists.gnu.org/archive/html/emacs-orgmode/2013-01/msg00888.html > > > --f46d040891519252fe04d50fd3fd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks for the -Q reminder. I get the same output if I run with emacs -Q (a= lthough I do have to add :results output to each block. I had that set as a= default in my init files).

I had the problem described in the footn= ote you listed, and that is why I am using python-mode 5.2, which doesn'= ;t have that issue.

John

-----------------------------------
J= ohn Kitchin
Associate Professor
Doherty Hall A207F
Department of C= hemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213 412-268-7803
http://kitchingroup.cheme.cmu.edu



On Wed, Feb 6, 2013 at 10:10 AM, Myles E= nglish <mylesenglish@gmail.com> wrote:

Hi John,

John Kitchin writes:

> I have been trying to use the :session feature of babel for python cod= e
> blocks. I have noticed a few things that might be areas for
> improvement. Some issues are related to what I think might be a need f= or
> sanitizing the code blocks and the output.
>
> I am using (insert (org-version)) 7.9.3a
> I am using python-mode 5.2 (more modern versions do not work with
> :session for me)
>
> The first small detail is illustrated here:
>
> #+BEGIN_SRC python :session
> a =3D 5
>
> b =3D 6
>
> print a + b
> #+END_SRC
>
> #+RESULTS:
> :
> : >>> >>> >>> 11
>
> In the output, there are three sets of >>>, due to the two em= pty
> lines. Compare this to
>
> #+BEGIN_SRC python :session
> a =3D 5
> b =3D 6
> print a + b
> #+END_SRC
>
> #+RESULTS:
> :
> : >>> 11
>
> I think it would be nice to sanitize the python code block sent to the=
> interpreter to eliminate the empty lines, and avoid the multiple >&= gt;> in
> output. It would also be nice to have an option to not print those at<= br> > all.
>
> The second issue is related. The following code does not work for me i= n
> :session, but it works fine as a standalone block. The issue is relate= d
> to the presence of an empty line in the function definition. I like > whitespace like this in functions sometimes for readability.
>
> #+BEGIN_SRC python :session
> def func(x):
> =A0 =A0 'doc string'
>
> =A0 =A0 return x**2
>
> print func(2)
> #+END_SRC
>
> #+RESULTS:
> :
> : ... >>> =A0 File "<stdin>", line 1
> : =A0 =A0 return x**2
> : =A0 =A0 ^
> : IndentationError: unexpected indent
> : >>> None
>
> Removing the blank line works fine, but still has some non-pretty
> output.
>
> #+BEGIN_SRC python :session
> def func(x):
> =A0 =A0 'doc string'
> =A0 =A0 return x**2
>
> print func(2)
> #+END_SRC
>
> #+RESULTS:
> :
> : ... ... >>> 4
>
> One of the ellipsis is due to the doc string.
> #+BEGIN_SRC python :session
> def func(x):
> =A0 =A0 return x**2
>
> print func(2)
> #+END_SRC
>
> #+RESULTS:
> :
> : ... >>> 4
>
> Interestingly, this did not work, because there is no empty line after=
> the function definition. So, sanitizing could be tricky.
>
> #+BEGIN_SRC python :session
> def func(x):
> =A0 =A0 'doc string'
> =A0 =A0 return x**2
> print func(2)
> #+END_SRC
>
> #+RESULTS:
> :
> : ... ... =A0 File "<stdin>", line 4
> : =A0 =A0 print func(2)
> : =A0 =A0 =A0 =A0 ^
> : SyntaxError: invalid syntax
>
> I think if there was a way to strip all the empty lines from the input= ,
> it would go a long way to making the output look like what I think mos= t
> people would expect and want.
>
> Anyway, those are the examples I wanted to highlight in this
> post.
>
>
> 1. Do you see similar behavior, or is this a feature of my setup?

I haven't tried your examples (no time) but you would be ab= le to tell if
it was a feature of your setup by making a minimum working example and
starting emacs with 'emacs -Q'. =A0If you see the thread in the foo= tnote
it contains such an example.

> 2. Is there any interest in sanitizing the input and output of a
> python :session to get prettier output? if so, Any hints on where to > start with that?

I had some problems recently with :session, there was a short discuss= ion[1],
and last I heard the maintainer of python-mode.el is looking into it.

Myles

Footnotes:
[1] =A0https://lists.gnu.org/archive/html/emacs-o= rgmode/2013-01/msg00888.html



--f46d040891519252fe04d50fd3fd--