Introduction to Python Scripts

The Scripting Facility for IBM® SPSS® Statistics provides the ability to create Python ® scripts that operate on the IBM SPSS Statistics user interface, manipulate output objects, and run command syntax. This feature requires the IBM SPSS Statistics - Integration Plug-in for Python, which is installed by default with your IBM SPSS Statistics product..

A companion interface is available for creating Python programs that enable you to control the flow of command syntax jobs, read and write data, and create custom procedures. See the topic Introduction to Python Programs for more information.

Scope

You can run Python scripts directly from within IBM SPSS Statistics, from within Python programs, or from an external Python process, such as a Python IDE or the Python interpreter.

Python Script Run from IBM SPSS Statistics. You can run a Python script from Utilities>Run Script or from the Python script editor which is launched when opening a Python file (.py) from File>Open>Script. Scripts run from the Python editor that is launched from IBM SPSS Statistics operate on the IBM SPSS Statistics client that launched the editor. This allows you to debug your Python code from a Python editor.

Python Script Run from an External Python Process. You can run a Python script from any external Python process, such as a Python IDE that is not launched from IBM SPSS Statistics, or the Python interpreter. The script will attempt to connect to an existing IBM SPSS Statistics client. If more than one client is found, a connection is made to the most recently launched one. If an existing client is not found, the Python script starts up a new instance of the IBM SPSS Statistics client. By default, the Data Editor and Viewer are invisible for the new client. You can choose to make them visible or work in invisible mode with datasets and output documents.

Python Script Run from Python Program. You can run a Python script from a Python program by importing the Python module containing the script and calling the function in the module that implements the script. You can also call Python script methods directly from within a Python program. See the topic Running Python Scripts from Python Programs for more information.

Limitations

Help

General information on the Scripting Facility for IBM SPSS Statistics and additional information on Python scripts is available from Scripting with the Python Programming Language .