Python programs written to run in BEGIN PROGRAM blocks are easy to write and add lots of functionality to IBM SPSS Statistics.Â Many users have learned to create these. More users, though, do not know the Python language.
The extension command mechanism provides a way for users of traditional SPSS syntax to run Python programs written by someone else without needing any knowledge of Python.Â But the program must have been written as an extension command.Â While creating extension commands isn't hard, it does require some extra knowledge and work.Â (An article on how to do this is available on Developer Central.)
I have posted a new extension command, SPSSINC PROGRAM, that allows ordinary Python programs to be run with traditional syntax without the author having created an extension command: easy on the author and easy on the user.Often someone writes and shares a Python program for use via BEGIN PROGRAM that requires some input parameters.Â The BEGIN PROGRAM syntax does not allow for parameters, so the user must modify the program itself to specify these.Â If you know Python, this is not a problem, but many users are uncomfortable doing that, since the Python language is quite different from the traditional SPSS language.
A Python programmer would typically define a function or class with the requisite parameters and just modify the function call.Â An SPSS user might not know how to do that.
SPSSINC PROGRAM solves this problem.Â (Of course, extension commands solve this problem more generally, but they take extra work to create.) Â Suppose I have a program saved as mymodule.mypgm.py that does something to a pair ofÂ SPSS variables , and I want the variable names to beÂ parameters.Â Using SPSSINC PROGRAM, I would write
SPSSINC PROGRAM mymodule.mypgm firstvar secondvar.
firstvar and secondvar would be the parameter values passed to the program.Â SPSSINC PROGRAM ensures that mymodule.mypgm is called,Â makes the parameters available to the program, and handles various error conditions.
Instead of passing the parameters as function arguments, the parameters are set up as if they were a command line.Â The author of the program would access these in the traditional Python way via sys.argv, with the first parameter being the module and program name.Â It's just as if the program were being run from a command shell, except that the parameter values have been passed through the SPSS Universal Parser.Â Comments in the implementation module details the (small) differences this can produce in what the program sees.
So using SPSSINC PROGRAM is very easy on the Python programmer while still letting the user of the program work in the style he or she is comfortable with.Â The package also includes a dialog box built with the Custom Dialog Builder where the user can enter the program name and any parameters.