Q:

Using Python to run SPSS analyses and retrieve values (Python -> Spss -> Python)

I have spent a few days orientating myself to the spss and spssaux modules - which are great resources. Though I feel like I am missing some conceptual understanding because I can do basic things like retrieve value labels via spssaux.getValueLabels or spss.DataStep()
print spssaux.getValueLabels(2)
>>> {u'1': u'Neutral', u'0': u'Disagree', u'2': u'Agree'}

or 
dataset = spssDataset()
variable_list = dataset.varList
print variable_list[2].valueLabels.data
>>> {0.0: u'Disagree', 1.0: u'Neutral', 2.0: u'Agree'}

However, I'm struggling to figure out how to retrieve the actual data values.
I'm also having trouble figuring out how to retrieve the values from analyses and to use them in Python. At the moment I have been running analyses using spss.Submit(), but I suspect this is limited in terms of feeding values back to Python (i.e., feeding back means and significance values to Python, which can be then used in Python to make decisions).
If you have any suggestions for ideas, please note that I need to be operating within the Python environment as this data retrieval/analyses is incorporated into a broader Python program.
Thanks!

A:

The spss.Cursor class is a low level class that is rather hard to use.  The spssdata.Spssdata class provides a much friendlier interface.  You can also use the spss.Dataset class, which was modeled after Spssdata and has additional capabilities but is slower.
For retrieving Viewer output, the basic workhorse is OMS writing to the xml workspace or to new datasets.  You can use some functions in the spssaux module that wrap this.  createDatasetOuput simplifies creating datasets from tables.  createXmlOutput and the companion getValuesFromXmlWorkspace use the xml workspace.  Underneath the latter, the spss.EvaluateXPath api lets you pluck whatever piece of output you want from a table.
Also, if you are basically living in a Python world, have you discovered external mode?  This lets you run Statistics from an external Python program.  You can use your Python IDE to work interactively in the Python code and debug.  You just import the spss module and whatever else you need and use the provided apis as needed.  In external mode, however, there is no Viewer, so you can't use the SpssClient module apis.

