SPSS python 抛出不连续的错误
SPSS python throws discontinuous errors
受到问答的启发写了一个简单的"set current working directory"。但有时它会抛出这个错误:
>Warning # 6894. Command name: BEGIN PROGRAM
>The external program exit unexpectedly and lost its content, a new exteranl
>program will startup to execute the rest of job.
我不能将此错误导致我的代码中有任何特殊之处,SPSS 有时会抛出此错误,如果我继续执行该程序,有时它会工作,有时它不会出现上述错误,所以感觉客户端有时是没有开始什么的。
我的程序如下所示:
def Run(args):
import spss, spssaux, SpssClient, os
SpssClient.StartClient()
my_filepath_ = os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath())
my_filepath = spssaux._smartquote(my_filepath_)
spss.Submit("CD %s ." % (my_filepath))
SpssClient.StopClient()
我还设置了一个 XML 文件并将其与 python 文件一起放在 EXTPATHS EXTENSIONS 目录中。
<Command xmlns="http://xml.spss.com/extension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="SET_CWD" Language="Python">
</Command>
通过在语法文件中键入 SET_CWD
来调用它,SET_CWD
也是 .py- 和 .xml 文件的名称,SET_CWD.py
和SET_CWD.xml
.
我把这两个文件保存在文件夹C:\ProgramData\IBM\SPSS\Statistics\extensions
MYSET_CWD.py
def Run(args):
import spss, spssaux, SpssClient, os
SpssClient.StartClient()
my_filepath_ = os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath())
my_filepath = spssaux._smartquote(my_filepath_)
spss.Submit("CD %s ." % (my_filepath))
SpssClient.StopClient()
MYSET_CWD.xml
<Command xmlns="http://xml.spss.com/extension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MYSET CWD" Language="Python">
</Command>
保存语法中,必须保存(否则会报错No valid directory specification was found.
),我运行:
MYSET CWD.
并且当前工作目录更改为 MYSET CWD.
来自 运行 的语法文件的保存位置。 运行宁SHOW directory.
前后MYSET CWD.
.
证实了这一点
注意 GetDocumentPath
"Returns the path and file name of the syntax file associated with this syntax document object, or the empty string if the syntax document is not associated with a file."
所以你应该在尝试做任何其他事情之前测试那个条件。
XML文件与此无关。如果不正确,当您在代码获得控制权之前尝试 运行 您的扩展命令时,您将收到错误消息。
在某些情况下,您可能没有指定的语法 window(或者它可能不会被保存)。
受到
>Warning # 6894. Command name: BEGIN PROGRAM
>The external program exit unexpectedly and lost its content, a new exteranl
>program will startup to execute the rest of job.
我不能将此错误导致我的代码中有任何特殊之处,SPSS 有时会抛出此错误,如果我继续执行该程序,有时它会工作,有时它不会出现上述错误,所以感觉客户端有时是没有开始什么的。 我的程序如下所示:
def Run(args):
import spss, spssaux, SpssClient, os
SpssClient.StartClient()
my_filepath_ = os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath())
my_filepath = spssaux._smartquote(my_filepath_)
spss.Submit("CD %s ." % (my_filepath))
SpssClient.StopClient()
我还设置了一个 XML 文件并将其与 python 文件一起放在 EXTPATHS EXTENSIONS 目录中。
<Command xmlns="http://xml.spss.com/extension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="SET_CWD" Language="Python">
</Command>
通过在语法文件中键入 SET_CWD
来调用它,SET_CWD
也是 .py- 和 .xml 文件的名称,SET_CWD.py
和SET_CWD.xml
.
我把这两个文件保存在文件夹C:\ProgramData\IBM\SPSS\Statistics\extensions
MYSET_CWD.py
def Run(args):
import spss, spssaux, SpssClient, os
SpssClient.StartClient()
my_filepath_ = os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath())
my_filepath = spssaux._smartquote(my_filepath_)
spss.Submit("CD %s ." % (my_filepath))
SpssClient.StopClient()
MYSET_CWD.xml
<Command xmlns="http://xml.spss.com/extension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MYSET CWD" Language="Python">
</Command>
保存语法中,必须保存(否则会报错No valid directory specification was found.
),我运行:
MYSET CWD.
并且当前工作目录更改为 MYSET CWD.
来自 运行 的语法文件的保存位置。 运行宁SHOW directory.
前后MYSET CWD.
.
注意 GetDocumentPath "Returns the path and file name of the syntax file associated with this syntax document object, or the empty string if the syntax document is not associated with a file."
所以你应该在尝试做任何其他事情之前测试那个条件。
XML文件与此无关。如果不正确,当您在代码获得控制权之前尝试 运行 您的扩展命令时,您将收到错误消息。
在某些情况下,您可能没有指定的语法 window(或者它可能不会被保存)。