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
- 뇌출혈
- 파이썬
- 급성심근경색증
- 프론트엔드
- 납입
- Java
- python
- 추가납입
- 코딩
- 보험료
- 중도인출
- 수수료
- 변환
- 특약
- 교보
- PythonProgramming
- javascript
- 리스트
- 가입
- 심장질환
- 웹개발
- 인출수수료
- 프로그래밍
- 보험
- Vue.js
- 자바스크립트
- jQuery
- 교보생명
- 문자열
- 사망
Archives
- Today
- Total
SeouliteLab
[Python/파이썬] Text 파일 읽고 쓰는 방법 본문
Python에서는 텍스트 파일을 읽고 쓰는 기능을 제공합니다. 파일을 읽어오거나 쓰는 과정은 매우 중요하며, 이를 통해 데이터를 저장하고 처리할 수 있습니다. 이번에는 파일을 읽고 쓰는 세 가지 주요 작업에 대해 알아보겠습니다: read, write, append.
1. 파일 읽기 (read)
file_path = "example.txt"
with open(file_path, "r") as file:
content = file.read()
print(content)
2. 파일 쓰기 (write)
file_path = "example.txt"
with open(file_path, "w") as file:
file.write("This is a sample text.\n")
file.write("Writing text to a file in Python.\n")
3. 파일 추가하기 (append)
file_path = "example.txt"
with open(file_path, "a") as file:
file.write("Appending text to an existing file.\n")
file.write("Adding more content using Python.\n")
'프로그래밍' 카테고리의 다른 글
[Python/파이썬] 소수점 버리는 방법 (0) | 2024.03.01 |
---|---|
[Python/파이썬] 두 개의 리스트 하나로 합치는 방법 (0) | 2024.03.01 |
[Python/파이썬] 문자열 비교 방법 (0) | 2024.03.01 |
[Python/파이썬] os.walk()를 사용한 디렉토리 및 파일 탐색하기 (0) | 2024.03.01 |
[Python/파이썬] HTTP 요청을 처리 (feat.requests 라이브러리) (0) | 2024.02.29 |