From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: odd/unexpected behavior with Python src blocks Date: Sun, 28 Sep 2014 18:11:46 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYMhV-0000Xk-Kj for emacs-orgmode@gnu.org; Sun, 28 Sep 2014 18:12:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYMhP-0006c2-7Z for emacs-orgmode@gnu.org; Sun, 28 Sep 2014 18:12:17 -0400 Received: from plane.gmane.org ([80.91.229.3]:44588) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYMhO-0006br-WF for emacs-orgmode@gnu.org; Sun, 28 Sep 2014 18:12:11 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XYMhH-0007p9-Vw for emacs-orgmode@gnu.org; Mon, 29 Sep 2014 00:12:03 +0200 Received: from c-24-3-17-30.hsd1.pa.comcast.net ([24.3.17.30]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 29 Sep 2014 00:12:03 +0200 Received: from jkitchin by c-24-3-17-30.hsd1.pa.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 29 Sep 2014 00:12:03 +0200 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: emacs-orgmode@gnu.org * Odd behavior in python src-blocks in org-mode I found that some code blocks in Python execute due to apparently silent errors! here is how to reproduce it with a vanilla emacs -q. #+BEGIN_SRC emacs-lisp (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t) (python . t))) (setq org-confirm-babel-evaluate nil) #+END_SRC #+RESULTS: This block should raise an error (and does) because k is not defined. #+BEGIN_SRC python def f(y, x): return k * y print(f(1, 0)) #+END_SRC #+RESULTS: It raises this error. #+BEGIN_EXAMPLE Traceback (most recent call last): File "", line 4, in File "", line 2, in f NameError: global name 'k' is not defined #+END_EXAMPLE However, this code block actually executes, and gives the wrong answer! If I open the source block in Python mode, it does not run without error. #+BEGIN_SRC python :results output from scipy.integrate import odeint def f(y, x): return k * y print(odeint(f, 1, [0, 1])) #+END_SRC #+RESULTS: : [[ 1.] : [ 1.]] Here is the correct answer. #+BEGIN_SRC python :results output from scipy.integrate import odeint k = -1 def f(y, x): return k * y print(odeint(f, 1, [0, 1])) #+END_SRC #+RESULTS: : [[ 1. ] : [ 0.36787947]] I am not sure why this happens, but it seems like incorrect behavior to me. -- ----------------------------------- John Kitchin http://kitchingroup.cheme.cmu.edu