일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 파이썬
- c#
- math
- Tkinter
- gas
- Github
- PySpark
- PostgreSQL
- GIT
- string
- list
- google apps script
- PANDAS
- Redshift
- Google Excel
- Excel
- numpy
- matplotlib
- django
- Java
- Python
- Google Spreadsheet
- SQL
- array
- Kotlin
- hive
- Mac
- dataframe
- Apache
- Today
- Total
목록Python/Python os (9)
달나라 노트
import os print(os.getcwd()) os.getcwd는 현재 code가 실행되는 위치나 실행된 code가 적힌 python file이 있는 directory를 반환합니다.
import os os.rename("text.txt", "test.txt") rename은 명시된 file의 이름을 변경하는 역할을 합니다. 위 코드는 해당 코드가 실행되는 디렉토리와 동일한 위치에 있는 text.txt라는 파일의 이름을 test.txt로 변경합니다.
import os os.unlink('test.txt') unlink는 어떤 파일을 삭제하는 기능을 제공합니다. 위 코드는 위 파이썬 파일이 존재하는 동일 디렉토리에 있는 test.txt 파일을 제거합니다.
os.makedirs os.makedirs은 디렉토리를 만들어주는 기능을 제공합니다. 아래와 같은 디렉토리 구조가 있다고 가정해봅시다. --- dir |--- test.py |--- test_2 |--- test.xlsx 현재 코드는 test.py에 적히고 있습니다. 만약 test.py와 동일한 디렉토리에 testing이라는 디렉토리를 새로 생성하고싶다면 아래처럼 하면 됩니다. import os os.makedirs(name='testing/', exist_ok=True) - Output --- dir |--- test.py |--- teseting |--- test_2 |--- test.xlsx 그러면 testing이라는 디렉토리가 생성된 것을 볼 수 있습니다. 위 예시에서 exist_ok=True라는..