I am testing the possibility of including python code in org-mode files in emacs. As it is my first time with I ran into an error that probably it is easy to fix, but I cannot see the solution. I want to define some onstants and functions and use them later in the file. If I do this witho only one function there is no problem, as in this simple example:
* Initialization block containing constants and function definition
#+NAME: init_block
#+BEGIN_SRC python :session
# Constants
a_constant = 287.
#
#
##########################
def m_T(E_val):
import numpy as np
A_val = 6.1094
return A_val*np.log(E_val/A_val)
#+END_SRC
#+RESULTS: init_block
* Example
#+BEGIN_SRC python :session :results output
print "Hello, world! This is my zero trial ", a_constant
print m_T(10.)
#+end_src
#+RESULTS:
: Hello, world! This is my zero trial 287.0
: 3.01044670959
However, when I try to include the definition of two functions errors pop up:
* Initialization block containing constants and function definition
#+NAME: init_block
#+BEGIN_SRC python :session b
# Constants
a_constant = 287.
#
#
##########################
def m_T(E_val):
import numpy as np
A_val = 6.1094
return A_val*np.log(E_val/A_val)
#################
b_constant = 287.
#################
def m_E(T_val):
import numpy as np
A_val = 6.1094
return A_val*np.exp(T_val/A_val)
#################
c_constant = 287.
##########################
#+END_SRC
#+RESULTS: init_block
* Example
#+BEGIN_SRC python :session b :results output
print "Hello, world! This is my zero trial ", a_constant, b_constant, c_constant
print m_T(10.)
print m_E(12.3)
#+end_src
#+RESULTS:
#+begin_example
Hello, world! This is my zero trial 287.0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b_constant' is not defined
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'm_T' is not defined
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'm_E' is not defined
#+end_example
I would appreciate any help to understand what am I doing wrong in this case.