0

I have written a simple function in python that I want executed by Jython's PythonInterpreter. The problem is, I'm not sure where the .py class needs to go.

I have tried in the same package as the Java class, the same working directory as well as another folder.

Importing files from different folder

I am interested in the above method, but I do not want to use an absolute path as I intend to make this program available for other people to use.

Here is my workspace layout:

layout

I will be invoking the function in myscraper.py from EntryManagement.java. The function is defined as follows:

def validateUrl(url):
  try: 
    uReq(url)
    return(1)
  except URLError:
    return(0)

How do I do this?

Rui
  • 55
  • 1
  • 6

1 Answers1

0

Used OS to get the current working directory and worked from there, using sys.path

interpreter.exec("sys.path.insert(0, os.getcwd() + '\\src\\python')");
interpreter.exec("from myscraper import validateUrl");
Rui
  • 55
  • 1
  • 6