emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Andrea Crotti <andrea.crotti.0@gmail.com>
Cc: Org mode <emacs-orgmode@gnu.org>
Subject: Re: [babel] python sessions
Date: Sun, 03 Jul 2011 12:13:19 -0600	[thread overview]
Message-ID: <87zkkvkzb4.fsf@gmail.com> (raw)
In-Reply-To: sa0ei27cnpj.fsf@gmail.com

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> Eric Schulte <schulte.eric@gmail.com> writes:
>>
>> This is true, in addition to being a language which is dependent upon
>> whitespace characters, python has been tricky due to the many
>> independent inferior python modes (python.el, python-mode.el, etc...)
>> and to the fact that I personally and not very familiar with the
>> language.
>
> That is indeed a problem (also in cedet for example) and I really would
> like to have just one and working well python mode, not a thousand.. 
>

From what I hear the situation should improve in Emacs24, as there is a
ground up re-write which should contain much of the functionality of
python-mode.el with the Emacs-amenable license of python.el.

>
>>
>> I've just pushed up a patch which should improve upon the python session
>> behavior.  After this patch your example returns the following
>> results...
>>
>> #+begin_src python :session :results silent
>>   def var(x):
>>       return float(x ** 2)
>> #+end_src
>>
>> #+begin_src python :session :result value
>>   def var2(x):
>>       return x ** 2 * var(x)
>>   
>>   var2(10)
>> #+end_src
>>
>> #+results:
>> : 10000.0
>>
>
> That example now works like a charm
> But here still I get that string, but if I tangle the file I get the
> correct result, any idea?
>

The eoe string will only even appear in session output when there is no
other result returned by the code block.  I've just pushed up a small
change which should fix this situation.

The eoe will never appear in tangled code as it is part of the
interactive session evaluation.

Best -- Eric

>
> #+begin_src python :session :tangle myset.py :results silent
>   class MySetList(object):
>   
>       def __init__(self):
>           self._set = []
>   
>       def add(self, el):
>           if el not in self._set:
>               self._set.append(el)
>   
>       # implementation of other typical set functions
> #+end_src
>
> #+begin_src python :session :tangle myset.py :results silent
>   class MySetDict(object):
>   
>       def __init__(self):
>           self._dic = {}
>   
>       def add(self, el):
>           if el not in self._dic:
>               # we only care about the keys
>               self._dic[el] = None
> #+end_src
>
> #+begin_src python :session :tangle myset.py :results silent
>   class MySetSet(object):
>       def __init__(self):
>           self._set = set()
>       
>       def add(self, el):
>           self._set.add(el)
> #+end_src
>
>
> #+begin_src python :session :exports both :tangle myset.py
>   import timeit
>   import random
>   
>   NUM_ELS = 100
>   
>       
>   def add_many_to_set(set_type):
>       m = set_type()
>       for i in range(NUM_ELS):
>           m.add(i)
>   
>   
>   def test_impl(set_type):
>       to_import = """
>   from __main__ import add_many_to_set
>   from __main__ import %s"""
>   
>       name = set_type.__name__
>       print("testing %s" % name)
>       return timeit.timeit("add_many_to_set(%s)" % name,
>                            setup=(to_import % name))
>   
>   
>   test_impl(MySetList), test_impl(MySetDict), test_impl(MySetSet)
>   
> #+end_src

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

  reply	other threads:[~2011-07-03 18:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-03 12:18 [babel] python sessions Andrea Crotti
2011-07-03 15:15 ` Eric Schulte
2011-07-03 16:51   ` Andrea Crotti
2011-07-03 18:13     ` Eric Schulte [this message]
2011-07-03 18:54       ` Andrea Crotti
2011-07-04 17:23         ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zkkvkzb4.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=andrea.crotti.0@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).