반응형
os.path.realpath(__file__)
파일의 실제 경로 + 파일명을 리턴한다.
os.path.realpath(__file__) 의 경우 현재 파일(.py 형식의 파일 안에 있는 내용이라면)의 절대 경로를 리턴한다.
realPath = os.path.realpath(__file__) print realPath ======================
/home/username/Example/test.py |
os.path.dirname - 폴더 경로
파일의 경로만 리턴한다.
dirName = os.path.dirname(realPath) print dirName ====================== /home/username/Example |
os.path.join - 경로, 폴더명
경로를 add 한다.
joinPath = os.path.join(dirName, "addDir") print joinPath ======================
/home/username/Example/addDir |
joinPath = os.path.join(dirName, "addDir", "secondAddDir", "thirdAddDir") print joinPath ======================
/home/username/Example/addDir/secondAddDir/thirdAddDir |
반응형
'IT > 언어' 카테고리의 다른 글
Caused by: java.util.zip.ZipException: error in opening zip file (0) | 2019.07.01 |
---|---|
spring boot embedded tomcat letsencrypt ssl 적용 (0) | 2019.02.08 |
[c#] 파일 출력 (0) | 2014.08.19 |
페이징 처리용 소스(예제?) (0) | 2014.07.08 |
POI Excel 파일 쓰기 (0) | 2014.06.26 |