?利用Python的os.path.split()函数可以将文件路径拆分成文件夹路径和文件名;
?利用Python的os.path.join()函数可以将文件夹路径和文件名合并成文件路径。
?利用Python的os.path.splitext()函数可以将含后缀的文件名分割为文件名和后缀名。
if __name__ == '__main__':
file_In = "D:\\Data\\DataIn\\climate.xlsx"
(filepath, tempfilename) = os.path.split(file_In)
print(filepath)
print(tempfilename)
(filename, extension) = os.path.splitext(tempfilename)
print(filename)
print(extension)
file_out = os.path.join(filepath, tempfilename)
print(file_out)
Data=pd.read_excel(file_out)
print(Data.size)
输出结果为:
C:\ProgramData\Anaconda3\python.exe D:/Data_program/Python_program/Extract_NC.py
D:\Data\DataIn
climate.xlsx
climate
.xlsx
D:\Data\DataIn\climate.xlsx
128064
Process finished with exit code 0
|