Date: Thu, 15 Dec 2005 21:23:08 -0500
Reply-To: Raynald Levesque <email@example.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Raynald Levesque <firstname.lastname@example.org>
Subject: RE: Python and SPSS syntax - do they behave like one singl
Content-type: text/plain; charset=iso-8859-1
Personnaly I am thrilled about the opportunities that python brings to SPSS
programming. For one thing Python works synchronously with SPSS syntax.
My website includes 2 methods to pass an argument from SPSS syntax to
python. A third and better method (which does not use a file to pass the
information) uses a DATAFILE ATTRIBUTE to pass the argument. An added
advantage of DATAFILE ATTRIBUTE is that it does not require a data pass.
GET FILE='c:\Program Files\SPSS\cars.sav'.
DATAFILE ATTRIBUTE ATTRIBUTE=pythonArg('kkk is my argument').
import spss, spssaux
handle, failcode = spssaux.CreateXMLOutput(r"DISPLAY ATTRIBUTE.",
"File Information", visible=False)
print "failcode is " , failcode
data_attrib = spssaux.GetValuesFromXMLWorkspace(\
handle, "Datafile Attributes", rowCategory="pythonArg",
print "attribute:", data_attrib
print "*** Arguments was missing or was not correctly setup."
I wish to thank Jon Peck for helping me make the above work.
Since attribute values can be up to 32,767 bytes, the above approach can
easily be adapted to pass many arguments by simply separating them with ";"
or some other separators.
The way I see it, there will exist many situations where it will be required
to pass arguments from SPSS syntax to python.
Here is such an example:
Python is good at determining whether a given variable exists and whether it
is numeric or string. In flexible program, this variable may change from one
run to the next and this creates the need to pass the variable name to
Raynald Levesque Raynald@spsstools.net
Visit my SPSS site: http://www.spsstools.net
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
Sent: December 14, 2005 9:38 AM
Subject: Python and SPSS syntax – do they behave like one single
maybe some of you are also thinking about using python for their SPSS
programming (python is more or less integrated in SPSS 14). I would enjoy
some discussion about the use of it.
My hope is that syntax and python might integrate so well that they behave
as one single programming language (which is, in my view, not the case with
syntax and Sax Basic). A promising thing is that you can directly submit
variable values from python to SPSS.
On the other hand, apparently you cannot do the same thing the other way
round, i.e. with macro variables. There seems to be a solution to the
problem (http://www.spsstools.net/Python/PassAnArgumentToPython.SPS), which
involves writing to an external file and rereading it. Personally I am
afraid of this method, because I often had problems with it (i.e. sometimes
the file could not be opened) and I find it makes it more difficult to read
and understand the code. But I wonder if it is at all necessary to pass
arguments to python, because if you abstain from macros I don ´t see the
need for arguments to be passed to python (apart from macro variables
python can access all other SPSS objects directly, I understand).
Well, as you see, I find it quite hard to tell in advance, how well python
works with SPSS and what problems might appear. I do not want to spend a
lot of time and money (for upgrading to SPSS 14) and then discover that I
could as well have stack to macros and Sax Basic. I am looking very much
forward to your thoughts and comments.