title: Calling python module from Java
body: <p>I want to call a function from a python module from Java using "PythonInterpreter" and here's my Java code</p>
  
  <pre><code>PythonInterpreter interpreter = new PythonInterpreter();
  
  interpreter.exec("import sys\nsys.path.append('C:\\Python27\\Lib\\site-packages')\nimport helloworld");
  
  PyObject someFunc = interpreter.get("helloworld.getName");
  
  PyObject result = someFunc.__call__();
  
  String realResult = (String) result.__tojava__(String.class);
  
  System.out.println(realResult);
  </code></pre>
  
  <p>and the Python code (helloworld.py) is below:</p>
  
  <pre><code>    from faker import Factory
      fake = Factory.create()
  
      def getName():
         name = fake.name()
         return name  
  </code></pre>
  
  <p>The problem I'm facing is while I'm calling interpreter.get when it returns a null PyObject.</p>
  
  <p>Any idea what's going wrong? The python code runs fine from IDLE</p>
  
  <h1>EDIT</h1>
  
  <p>I just did a bit of change in the code as below</p>
  
  <pre><code>PythonInterpreter interpreter = new PythonInterpreter();
  
  interpreter.exec("import sys\nsys.path.append('C:\\Python27\\Lib\\site-packages')\nimport helloworld");
  
  
  PyInstance wrapper = (PyInstance)interpreter.eval("helloworld" + "(" + ")");  
  
  PyObject result = wrapper.invoke("getName()");
  
  String realResult = (String) result.__tojava__(String.class);
  
  System.out.println(realResult);
  </code></pre>
  
  <p>and I introduced a class in my python module</p>
  
  <pre><code>from faker import Factory
  
  class helloworld:
  
  def init(self):
      fake = Factory.create()
  
  def getName():
      name = fake.name()
      return name 
  </code></pre>
  
  <p>Now am getting the error below</p>
  
  <pre><code>Exception in thread "main" Traceback (innermost last):
    File "&lt;string&gt;", line 1, in ?
  TypeError: call of non-function (java package 'helloworld')
  </code></pre>