Python as a scripting language
JavaScript is a default scripting language in Etlworks Integrator. All of the examples in this documentation were created for JavaScript.
It is, however, possible to use Python instead.
Etlworks Integrator includes a library Jython, which adds Python to the list of the supported scripting languages. Currently, Jython supports Python 2.7.
How to write scripts in Python
Step 1. Everywhere where there is a scripting text area, click the Open in Editor
button.
Step 2. Click Select Language
and choose Phyton
.
Step 3. Write code in Python.
How to import Java classes and packages into the Python script
To access the classes provided by the Etlworks Java API, you need to import a particular package and class. It is possible to import multiple packages and classes into the same Python program.
For example:
from org.jsoup import Jsoup
from com.toolsverse.etl.core.task.common import FileManagerTask
from com.toolsverse.util import TypedKeyValue, Utils
from java.util import ArrayList
// the rest of the code
The same Java packages and classes that are available from JavaScript are also available from Python.
How to return a value from the Python script
If the Python code needs to return a value, for example, when calculating a field's value on the fly or setting the loop conditions, call scriptResult.setResult(the_value_that_you_want_to_return)
.
For example:
if evals < files.size():
fileFrom = files.get(evals).getKey()
fileTo = files.get(evals).getValue() + '.xlsx'
scriptResult.setResult(fileFrom)
This is different from JavaScript were the last calculated expression or a value
variable can be used as a return value.
Comments
0 comments
Please sign in to leave a comment.