반응형
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 |
Tags
- Java
- PANDAS
- string
- hive
- google apps script
- PySpark
- PostgreSQL
- Excel
- matplotlib
- GIT
- c#
- list
- Tkinter
- Redshift
- Github
- dataframe
- Google Excel
- Google Spreadsheet
- 파이썬
- Apache
- SQL
- numpy
- gas
- array
- math
- Kotlin
- Python
- Presto
- django
Archives
- Today
- Total
달나라 노트
Python pathlib : Path.suffix (파일의 확장자 추출, file extension) 본문
Python/Python ETC
Python pathlib : Path.suffix (파일의 확장자 추출, file extension)
CosmosProject 2026. 2. 13. 17:59728x90
반응형
pathlib에서 suffix 속성을 이용하면 파일의 확장자를 받을 수 있습니다.
from pathlib import Path
dir_path = '/Users/Documents/code/pythonProject/h_2.py'
# Create a Path object
obj_path = Path(dir_path)
# Get extension through suffix attribute
extension = obj_path.suffix
# Show extension
print(extension)
-- Result
.py
- obj_path = Path(dir_path)
먼저 Path를 통해 특정 directory에 존재하는 파일에 대한 object를 만듭니다.
그러면 이 object에는 파일에 대한 다양한 정보가 담겨있게 되죠.
- extension = obj_path.suffix
그리고 이렇게 suffix property를 이용해서 파일의 확장자 정보를 불러오는겁니다.
728x90
반응형
'Python > Python ETC' 카테고리의 다른 글
Comments