반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- PANDAS
- hive
- Java
- string
- Google Excel
- Google Spreadsheet
- Github
- gas
- Python
- Redshift
- math
- 파이썬
- django
- Kotlin
- Excel
- c#
- GIT
- Apache
- SQL
- array
- PySpark
- Tkinter
- Presto
- google apps script
- matplotlib
- PostgreSQL
- dataframe
- list
- numpy
Archives
- Today
- Total
달나라 노트
Python Basic : __file__ (실행중인 python file의 경로 반환) 본문
Python/Python Basic
Python Basic : __file__ (실행중인 python file의 경로 반환)
CosmosProject 2021. 6. 26. 18:29728x90
반응형
python을 실행하면 기본적으로 설정되는 변수들이 있습니다.
그 중에서 __file__은 현재 python file이 존재하는 경로를 반환해줍니다.
print(__file__)
-- Result
/User/documents/code/test.py
만약 위 print구문이 적힌 파일이 /User/documents/code/test.py라는 경로에 존재하면
위 예시처럼 해당 파일의 절대 경로를 반환해줍니다.
import os
print (os.path.dirname(__file__))
-- Result
/User/documents/code
os library를 이용하여 파일 이름 없이 경로만 얻을 수도 있습니다.
728x90
반응형
'Python > Python Basic' 카테고리의 다른 글
| Python Basic : format (천단위 콤마 삽입하기) (0) | 2021.09.07 |
|---|---|
| Python Basic : __name__ (직접 실행/패키지 실행 구분하기) (0) | 2021.06.26 |
| Python Basic : try ~ except ~ else ~ finally (Error 발생 상황 다루기) (0) | 2021.06.26 |
| Python Basic : raise (강제로 Error 발생시키기) (0) | 2021.06.26 |
| Python Basic : replace (특정 문자 변경하기) (0) | 2021.06.14 |
Comments