The scripting context
The modeler.script
module provides the context
in which a script is executed. The module is automatically imported
into a 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 is being used to run any streams. - The
stream()
function can be used with stream and SuperNode scripts. This function returns the stream that owns either the stream script or the SuperNode script that is 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 is 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 stream at the time
the script was invoked (for example, the stream passed via the batch
mode -stream option), or None . |
Same as for stream() |
Not applicable |
Stream | Returns a session | Returns a stream | Same as for stream() |
Not applicable |
SuperNode | Returns a session | Returns a stream | Returns a SuperNode stream | 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 executing and returns the supplied integer exit
code.
One of the methods that is defined for a stream is runAll(List)
.
This method runs all executable nodes. Any models or outputs that
are generated by executing the nodes are added to the supplied list.
It is common for a stream execution to generate outputs such as models, graphs, and other output. To capture this output, a script can supply a variable that is 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.