在 SPSS 中,使用 Python 程序,有没有办法获取事件数据集的文件名?我不是在谈论数据集名称;我需要文件名。
SPSS_Path=os.path.dirname(SpssClient.GetActiveDataDoc().GetDocumentPath())
获取路径,我正在寻找类似的文件名
请您参考如下方法:
关键是 spssaux 模块,它与 Python Essentials 一起安装在 SPSS 23 中(可能不在旧版本中,但我无法测试它)。归功于 this old post在 IBM 论坛上。
begin program.
import spss,spssaux
#this gets the whole path+filename+fileextension into a string:
Data_Info=str(spssaux.GetDatasetInfo())
#find the position of the last "/" in the above string, to determine the path
Slash_Pos=Data_Info.rfind("/")
#find the position of the last ".", to determine file extension
Ext_Pos=Data_Info.rfind(".")
#get Active File name
SPSS_Name = Data_Info[Slash_Pos+1:Ext_Pos]
#get Active File Path
SPSS_Path=Data_Info[:Slash_Pos+1]
print (SPSS_Name, SPSS_Path)
end program.
