From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrea Crotti Subject: Re: [babel] python sessions Date: Sun, 03 Jul 2011 18:51:04 +0200 Message-ID: References: <87r5671jbz.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7BIT Return-path: Received: from eggs.gnu.org ([140.186.70.92]:42797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdPsy-0005Ol-6j for emacs-orgmode@gnu.org; Sun, 03 Jul 2011 12:51:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QdPsw-0000Z8-H9 for emacs-orgmode@gnu.org; Sun, 03 Jul 2011 12:51:07 -0400 Received: from mta-2.ms.rz.rwth-aachen.de ([134.130.7.73]:44988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdPsw-0000Yv-6G for emacs-orgmode@gnu.org; Sun, 03 Jul 2011 12:51:06 -0400 Received: from ironport-out-1.rz.rwth-aachen.de ([134.130.5.40]) by mta-2.ms.rz.RWTH-Aachen.de (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008)) with ESMTP id <0LNR005TNO54RU00@mta-2.ms.rz.RWTH-Aachen.de> for emacs-orgmode@gnu.org; Sun, 03 Jul 2011 18:51:04 +0200 (CEST) In-reply-to: <87r5671jbz.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: Eric Schulte Cc: Org mode Eric Schulte 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.. > > 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? --8<---------------cut here---------------start------------->8--- #+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 --8<---------------cut here---------------end--------------->8---