title: C++ Python import class; call methods
body: <p>I am using Python 2.7. It is not clear to me how to embed Python inside C++ as found here: <a href="http://docs.python.org/2.7/extending/embedding.html" rel="nofollow">http://docs.python.org/2.7/extending/embedding.html</a>. </p>
  
  <p>I have a simple python example here in a file named test.py:</p>
  
  <pre><code>class math:
      #def __init__(self):
      def add(self, num1, num2):
          return num1 + num2
  
      def subtract(self, num1, num2):
          return num1 - num2
  </code></pre>
  
  <p>From python, I would do something like this:</p>
  
  <pre><code>&gt;&gt;&gt; from test import math
  &gt;&gt;&gt; m = math()
  &gt;&gt;&gt; a = m.add(1, 2)
  &gt;&gt;&gt; s = m.subtract(1, 2)
  </code></pre>
  
  <p>I have the beginning of some C++ code to do this:</p>
  
  <pre><code>PyObject *pName, *pModule;
  Py_Initialize();
  pName = PyString_FromString("test");
  pModule = PyImport_Import(pName);
  </code></pre>
  
  <p>That seems to work just fine. But, that seems to be the equivalent of doing this in Python:</p>
  
  <pre><code>import test
  </code></pre>
  
  <p>How do I import the Python class math? </p>
  
  <p>Thanks</p>