2016-05-19 2 views
2

В SPSS, используя программу Python, есть способ получить имя файла Active Dataset? Я не говорю о имени набора данных; Мне нужно имя файла.SPSS Python получить имя активного набора данных

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

получает путь, и я ищу что-то подобное для файла

ответ

1

Ключ к этому был модуль 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. 
1

Да, эта функция была доступна в течение длительного времени. Обратите внимание: активный набор данных не всегда имеет имя файла.

Смежные вопросы