PyTHON의 유용한 경로 속성 :
from pathlib import Path
#Returns the path of the directory, where your script file is placed
mypath = Path().absolute()
print('Absolute path : {}'.format(mypath))
#if you want to go to any other file inside the subdirectories of the directory path got from above method
filePath = mypath/'data'/'fuel_econ.csv'
print('File path : {}'.format(filePath))
#To check if file present in that directory or Not
isfileExist = filePath.exists()
print('isfileExist : {}'.format(isfileExist))
#To check if the path is a directory or a File
isadirectory = filePath.is_dir()
print('isadirectory : {}'.format(isadirectory))
#To get the extension of the file
fileExtension = mypath/'data'/'fuel_econ.csv'
print('File extension : {}'.format(filePath.suffix))
산출:
절대 경로는 PYTHON 파일이 위치한 경로입니다.
절대 경로 : D : \ Study \ Machine Learning \ Jupitor Notebook \ JupytorNotebookTest2 \ Udacity_Scripts \ Matplotlib 및 seaborn Part2
파일 경로 : D : \ Study \ Machine Learning \ Jupitor Notebook \ JupytorNotebookTest2 \ Udacity_Scripts \ Matplotlib 및 seaborn Part2 \ data \ fuel_econ.csv
isfileExist : True
isadirectory : 거짓
파일 확장자 : .csv