Getting Started with Python Scripts

The basic structure of a Python script is:

import SpssClient
SpssClient.StartClient()
<Python language statements>
SpssClient.StopClient()

Example

This script accesses the designated output document and sets each of the pivot tables as selected.

import SpssClient
SpssClient.StartClient()

OutputDoc = SpssClient.GetDesignatedOutputDoc()
OutputItems = OutputDoc.GetOutputItems()

for index in range(OutputItems.Size()):
   OutputItem = OutputItems.GetItemAt(index)
   if OutputItem.GetType() == SpssClient.OutputItemType.PIVOT:
        OutputItem.SetSelected(True)
SpssClient.StopClient()

Target for Standard output

The Python print statement writes output to Python's standard output. When you run a Python script from Utilities>Run Script, Python's standard output is directed to a log item in the IBM SPSS Statistics Viewer.