SPSS Python 获取活动数据集的文件名
SPSS Python get filename of active dataset
在 SPSS 中,使用 Python 程序,有没有办法获取活动数据集的文件名?我不是在谈论数据集名称;我需要文件名。
SPSS_Path=os.path.dirname(SpssClient.GetActiveDataDoc().GetDocumentPath())
获取路径,我正在寻找与文件名类似的内容
关键是 spssaux 模块,它与 SPSS 23 中的 Python Essentials 一起安装(旧版本可能没有,但我无法测试)。归功于 IBM 论坛上的 this old post。
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.
是的,那个功能已经用了很长时间了。请注意,活动数据集并不总是具有文件名。
在 SPSS 中,使用 Python 程序,有没有办法获取活动数据集的文件名?我不是在谈论数据集名称;我需要文件名。
SPSS_Path=os.path.dirname(SpssClient.GetActiveDataDoc().GetDocumentPath())
获取路径,我正在寻找与文件名类似的内容
关键是 spssaux 模块,它与 SPSS 23 中的 Python Essentials 一起安装(旧版本可能没有,但我无法测试)。归功于 IBM 论坛上的 this old post。
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.
是的,那个功能已经用了很长时间了。请注意,活动数据集并不总是具有文件名。