The scripting context
The modeler.script
module provides the context in which a script runs. The
module is automatically imported into an SPSS® Modeler script at run time. The module
defines four functions that provide a script with access to its execution environment:
- The
session()
function returns the session for the script. The session defines information such as the locale and the SPSS Modeler backend (either a local process or a networked SPSS Modeler Server) that's being used to run any flows. - The
stream()
function can be used with flow and SuperNode scripts. This function returns the flow that owns either the flow script or the SuperNode script that's being run. - The
diagram()
function can be used with SuperNode scripts. This function returns the diagram within the SuperNode. For other script types, this function returns the same as thestream()
function. - The
supernode()
function can be used with SuperNode scripts. This function returns the SuperNode that owns the script that's being run.
The four functions and their outputs are summarized in the following table.
Script type | session() |
stream() |
diagram() |
supernode() |
---|---|---|---|---|
Standalone | Returns a session | Returns the current managed flow at the time the script was invoked (for
example, the flow passed via the batch mode -stream option), or
None . |
Same as for stream() |
Not applicable |
Flow | Returns a session | Returns a flow | Same as for stream() |
Not applicable |
SuperNode | Returns a session | Returns a flow | Returns a SuperNode flow | Returns a SuperNode |
The modeler.script
module also defines a way of terminating the script with an
exit code. The exit(exit-code)
function stops the script from
running and returns the supplied integer exit code.
One of the methods that's defined for a flow is runAll(List)
. This method runs
all executable nodes. Any models or outputs that are generated by running the nodes are added to the
supplied list.
It's common for a flow run to generate outputs such as models, graphs, and other output. To capture this output, a script can supply a variable that's initialized to a list. For example:
stream = modeler.script.stream()
results = []
stream.runAll(results)
When execution is complete, any objects that are generated by the
execution can be accessed from the results
list.