问题
I just want to only print my reslut to Spss cell called "vysledek", in python script. Ivot only two arrays, so i comper this arrays and count only in how many cases is the second one bigger than firts one, and wants to print the reslut to vysledek.
Begin program.
import spss, spssaux
spssaux.OpenDataFile('C:\Users\šoťa\Desktop\datacssd.sav')
dlist = ['PARLAMENTCSSD2010']
ilist = ['KRAJCSSD2012']
vlist = ['VYSLEDKY']
ddim = Len(dlist)
idim = Len(ilist)
For i In range(ddim):
If dlist[x] < ilist[x]:
Print ('the ilist is higher in cases: + '.')
spss.Submit(r"""
vlist[1]=vlist[1]+1
End program.
回答1:
Not sure exactly how the SPSS interface works but I suspect it's not working because nearly every line in your code is invalid Python syntax. Try converting to the the following:
import spss, spssaux
spssaux.OpenDataFile('C:\Users\šoťa\Desktop\datacssd.sav')
dlist = ['PARLAMENTCSSD2010']
ilist = ['KRAJCSSD2012']
vlist = ['VYSLEDKY']
ddim = len(dlist)
idim = len(ilist)
for i in range(ddim):
if dlist[x] < ilist[x]:
print ('the ilist is higher in cases: + .')
spss.Submit("vlist[1]=vlist[1]+1")
回答2:
I suspect that some capitalization-crazy tool broke the original post, but the problem remains the use of the Submit api. The argument to Submit is one or more lines of SPSS syntax, not what is shown above. If you accumulate the count within the Python code (and not in the character string vlist), you can just print it as an ordinary Python print statement.
If you want to turn this into a nice pivot table, you can use the spss.SimplePivotTable api.
来源:https://stackoverflow.com/questions/18190699/print-result-to-cell-spss-python-script