1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
* Pass an argument from SPSS to Python.

**************** One method: using label of a variable ********************.

* To pass an argument to Python, define variable PythonArg and

GET FILE='c:\program files\spss\employee data.sav'.
NUMERIC PythonArg.
VARIABLE LABEL PythonArg "127; var1".

BEGIN PROGRAM python.
12
13
14
15
16
17
18
import spss
lastVar = spss.GetVariableCount() - 1
if spss.GetVariableName(lastVar) == "PythonArg":
	argument = "\n***Python received the following argument: " + spss.GetVariableLabel(lastVar) 
else:
	argument = "\n***No arguments passed to Python"
print argument
19
20
21
22
23
24
25
26
27
28
29
30
31
32
END PROGRAM.

EXECUTE.
DELETE VAR PythonArg.


**************** Alternative method: using a text file  ********************.

* Note: This method is MORE promissing.

GET FILE='c:\program files\spss\employee data.sav'.
HOST COMMAND=['ECHO 127; var1 > c:\temp\PythonArg.txt'].

BEGIN PROGRAM python.
33
34
35
36
37
38
39
40
41
42
43
import spss, win32api

try:
	f = open(r'c:\temp\PythonArg.txt')
	arguments = f.readline()
	f.close()
	win32api.DeleteFile(r'c:\temp\PythonArg.txt')
	print "\n *** Python received the following arguments: " + arguments
except:
	print "\n***No arguments passed to Python"
print argument
44
45
46
END PROGRAM.

EXECUTE.