1

I have a python component that works independently and runs as a windows service. A particular file of this python does a specific job which i need to invoke using my java class. Since it's a production environment, .py file is not provided. To invoke a method "run" from .py file i am using the below code:

PyInterpreter py = new PyInterpreter();

py.execfile("C:\\Users\\narendrar\\Desktop\\hello.py");

PyInstance hello = py.createClass("Hello", "None");
    hello.invoke("run");

I want to perform similar operation, but with a compiled python file.

Narendra Rawat
  • 353
  • 2
  • 5
  • 17

1 Answers1

1

As you can see in the jython documentation about modules, a jython import isn't necessarily about Java packages.

In other words: you should be able to import/require python modules as well, making it possible to rely on your pyc files!

( remember: you can import pyc files, .py files only get pulled in if they are newer than the pyc - see here )

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • To give you the context, i am using jython library in my java maven project which uses PythonInterpreter to create java bytecode from py files. – Narendra Rawat Oct 15 '18 at 09:44