python으로 현재 디렉토리 위치를 알아내는 방법
조회수 60092회
1 답변
-
os.path에 해당 정보가 있습니다.
import os print (os.getcwd()) #현재 디렉토리의 print (os.path.realpath(__file__))#파일 print (os.path.dirname(os.path.realpath(__file__)) )#파일이 위치한 디렉토리
- getcwd() : 현재작업디렉토리(current working directory)를 나타내는 스트링을 리턴
__file__
: 파일의 path를 저장- realpath() : file이 symbolic link인 경우 원본 위치를 찾아줌
댓글 입력