SPSS Python获取活动数据集的文件名
在SPSS中,使用Python程序,是否有方法获取活动数据集的文件名?我不是说数据集名称;我需要文件名SPSS Python获取活动数据集的文件名,python,filenames,spss,Python,Filenames,Spss,在SPSS中,使用Python程序,是否有方法获取活动数据集的文件名?我不是说数据集名称;我需要文件名 SPSS_Path=os.path.dirname(SpssClient.GetActiveDataDoc().GetDocumentPath()) 获取路径,我正在查找与文件名类似的内容。关键是spssaux模块,它与SPSS 23中的Python Essentials一起安装(可能不在旧版本中,但我无法对其进行测试)。归功于IBM论坛 begin program. import sps
SPSS_Path=os.path.dirname(SpssClient.GetActiveDataDoc().GetDocumentPath())
获取路径,我正在查找与文件名类似的内容。关键是spssaux模块,它与SPSS 23中的Python Essentials一起安装(可能不在旧版本中,但我无法对其进行测试)。归功于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.
是的,这个功能已经使用很长时间了。请注意,活动数据集并不总是具有文件名