gpt4 book ai didi

python - SPSS Python 获取事件数据集的文件名

转载 作者:太空宇宙 更新时间:2023-11-04 03:13:05 24 4
gpt4 key购买 nike

在 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.

关于python - SPSS Python 获取事件数据集的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37326955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com