Getting Python node properties - 3 - 3.12

Data360 Analyze Server Help

Product type
Software
Portfolio
Verify
Product family
Data360
Product
Data360 Analyze
Version
3.12
Language
English
Product name
Data360 Analyze
Title
Data360 Analyze Server Help
Copyright
2023
First publish date
2016

Python nodes can be made to be generic and reusable by defining node properties, and accessing them from within the node code.

There are two mechanisms for accessing properties within a Python node:

Note: The recommended approach is to use the runtime property names to obtain node properties.

Using the run time property names

Note: When properties are retrieved using their run time property name, all of the required properties should be obtained and verified within the initialize method, see Initialize.

For example, in the Python2Implementation property you define a member PROPERTY_BASE, as follows:

PROPERTY_BASE = "ls.brain.node.sumExample"

This means that all properties will have the following run time property name format, where <runtime-property-name-extension> is the suffix of the run time property name:

PROPERTY_BASE.<runtime-property-name-extension>

For example, for the OutputFieldName property, the PROPERTY_BASE part of the run time property name is ls.brain.node.sumExample and the suffix is outputFieldName.

Therefore, within the initialize method of the node these properties are loaded into the variables on the BrainNode object as follows:

# Obtain the values set on the node propertiesself.outputAsDouble = self.properties.getBool(PROPERTY_BASE + ".outputAsDouble")self.inputFieldName = self.properties.getString(PROPERTY_BASE + ".inputFieldName")

Consider the first property from the above example. This code obtains the properties member from self.properties defined on the BrainNode interface. The code then attempts to access the boolean property called:

PROPERTY_BASE + ".outputAsDouble"

From the PROPERTY_BASE variable, this corresponds to the run time property name:

ls.brain.node.sumExample.outputAsDouble

This run time property name is used by the OutputAsDouble property.

With all of this put together, the following line states "obtain the Boolean property OutputAsDouble and store it on the outputAsDouble variable on this object":

self.outputAsDouble = self.properties.getBool( PROPERTY_BASE + ".outputAsDouble");
Tip: You can view advanced property details, including the Run Time Property Name by clicking the menu button to the right of a property on the Define tab of the Properties panel, then selecting Edit Details. The Edit Property Definition dialog opens, showing the Run Time Property Name at the bottom.

Multi-line properties

When the property is a multi-line property (i.e. any property which does not have a property type of "choice", "string", "filename", "password" or "boolean"), then a little bit more work needs to be done to extract the property value.

In such cases, the properties.getString("<Runtime Property Name>") mechanism will actually return a filename which corresponds to the file where the contents of the property value are stored. Therefore, after obtaining the filename, the property contents need to be extracted. The following example shows how to parse the contents of a multi-line property with the run time property name ls.brain.node.textProperty into an array of strings:

import os
…

def setup:
    self.textParamFilename = self.properties.getString("ls.brain.node.textProperty", '')    self.textParamLines= file(self.textParamFilename, "r").read()

Assuming that you just want the contents of the property in an array, where each element in the array corresponds to a line in the property, then this mechanism can be used for all of the multi-line property types.

Textual substitution of properties

Textual substitution can be used to access properties within the Python code, using the {{^propertyname^}} syntax, see Explicit property reference.

The following example shows the use of textual substitution to obtain the output field name:

self.outputFieldName = "{{^OutputFieldName^}}"
Note: Within the Python code itself, it is recommended to use the run time property name, rather than textual substitution. Using the run time property name is preferable as it allows greater control of errors that can occur during property evaluation.