SPSS python抛出不连续错误

2024-05-19 12:52:48 发布

您现在位置:Python中文网/ 问答频道 /正文

this问答的启发,我写了一个简单的“设置当前工作目录”。但有时会出现这样的错误:

>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.pySET_CWD.xml。你知道吗


Tags: 文件目录osmy错误xmlprogramcommand
2条回答

我将这两个文件保存在C:\ProgramData\IBM\SPSS\Statistics\24\extensions文件夹中

我的集_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()

我的集_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 返回与此语法文档对象关联的语法文件的路径和文件名,如果语法文档与文件没有关联,则返回空字符串

所以你应该在做其他事情之前测试一下这个条件。你知道吗

XML文件与此无关。如果不正确,则在代码获得控制之前尝试运行扩展命令时会出现错误。你知道吗

在某些情况下,您可能没有指定的语法窗口(或者可能没有保存)。你知道吗

相关问题 更多 >