我想从SPSS语法窗口运行两个Python 3脚本。可以使用BEGIN PROGRAM-END PROGRAM.
块或SCRIPT
命令来执行。这次,我需要使用第二条命令找到解决方案。
简化代码:
*** MACROS.
define export_tabs (!positional !tokens (1))
output modify
/select logs headings texts warnings pagetitles outlineheaders notes
/deleteobject delete = yes.
OUTPUT EXPORT
/CONTENTS EXPORT = visible LAYERS = printsetting MODELVIEWS = printsetting
/XLSX DOCUMENTFILE = "doc.xlsx"
OPERATION = createsheet
sheet = !quote(!unquote(!1))
LOCATION = lastcolumn NOTESCAPTIONS = no
!enddefine.
define matrix_tab (!positional !charend('/')
/!positional !charend('/')
/!positional !charend('/')
/!positional !charend('/')
/stat = !tokens (1))
!do !i !in (!3)
ctables
/mrsets countduplicates = no
/vlabels variables = !concat(!1,_,!2,_,!i) display = label
/table !concat(!1,_,!2,_,!i)
[rowpct.responses.count !concat(!unquote(!stat),"40.0"), totals[count f40.0]]
/slabels position = column visible = no
/clabels rowlabels = opposite
/categories variables = !concat(!1,_,!2,_,!i) order = a key = value
empty = include total = yes label = "VALID COUNT" position = after
/titles title = !upcase(!4).
!doend
!enddefine.
*** REPORT.
* Sheet 1.
output close all.
matrix_tab $Q1 / 1 / 1 2 / "QUESTION 1" / stat="pct".
script "C:\path\script 1.py".
script "C:\path\script 2.py".
export_tabs "Q1".
* Sheet 2.
output close all.
matrix_tab $Q2 / 2 / 3 4 / "QUESTION 2" / stat="pct".
script "C:\path\script 1.py".
script "C:\path\script 2.py".
export_tabs "Q2".
当我为第一张纸运行一个块时,一切正常。但是,当我为第二张纸运行一个块时,SPSS不会执行Python脚本,而是直接跳转到export_tabs
宏(是否存在同步问题?)。我认为问题可能出在我执行SCRIPT
命令的方式上。所以我尝试了这个:
script "C:\path\script 1.py" pythonversion = 3.
script "C:\path\script 2.py" pythonversion = 3.
但实际上SPSS-即使语法窗口将语法的这些部分涂上颜色-仍返回以下错误消息:
>Error # 3251 in column 152. Text: pythonversion
>The SCRIPT command contains unrecognized text following the the file
>specification. The optional parameter must be a quoted string enclosed in
>parentheses.
>Execution of this command stops.
你们中有人有这样的问题和/或知道为什么会这样吗?
注意:这两个Python脚本都可以从我安装的SPSS版本的Python 3.4.3外壳中顺利运行,因此我认为问题的核心不在这些代码内。
这似乎是实现此关键字的方式中的一个文档缺陷。我已经能够复制它,并通过IBM SPSS Statistics Development记录了一个缺陷。
在这种情况下,顺序很重要。而不是这样:
脚本“ C:\ path \ script 2.py” pythonversion = 3。
请尝试:
脚本pythonversion = 3“ C:\ path \ script 2.py”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句