0

I'm really new to Jython and I have a code like this:

    interpreter.exec("import sys\nsys.path.append('my-path')\nimport hello");
    PyObject someFunc = interpreter.get("getDriverObect");

someFunc is always null! Here is the corresponding code for python:

from selenium import webdriver

def getDriverObect():
    c = webdriver.Safari()
    return c

I tried the following the combination as well, nothing is working out:

PyObject someFunc = interpreter.get("hello.getDriverObect");
PyObject someFunc = interpreter.get("hello.getDriverObect()");
PyObject someFunc = interpreter.get("getDriverObect()");

Where I'm making mistake?

1 Answer 1

2

The function object is not available via interpreter.get("getDriverObject") unless you use from hello import getDriverObject.

Simplified hello.py:

def getDriverObject():
    return "TEST"

Java code:

interpreter.exec("from hello import getDriverObject");
PyObject func = interpreter.get("getDriverObject");
System.out.println(func);
System.out.println(func.__call__());

Output from the above:

<function getDriverObject at 0x2>
TEST

You could also do it like this:

interpreter.exec("import hello");
PyObject module = interpreter.get("hello");
PyObject func = module.__getattr__("getDriverObject");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.