SPSS Python获取活动数据的文件名

2024-05-16 04:56:13 发布

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

在SPSS中,使用Python程序,有没有办法获取活动数据集的文件名?我不是在说数据集名称;我需要文件名。在

SPSS_Path=os.path.dirname(SpssClient.GetActiveDataDoc().GetDocumentPath()) 

获取路径,我正在为文件名查找类似的内容


Tags: 数据path路径程序名称内容os文件名
2条回答

其中的关键是spssaux模块,它与pythonsessentials一起安装在spss23中(可能不在旧版本中,但我无法测试它)。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.

是的,这个功能已经有很长时间了。请注意,活动数据集并不总是有文件名。在

相关问题 更多 >