본문 바로가기

컴퓨터/Python

Python file

1. 파일 쓰기

with open("test.txt", "w") as file:
	file.write("Hello World!")

2. 파일 읽기

# 파일 열기
with open("test.txt", "r") as file:
    # 파일의 전체 내용을 읽어오기
    content = file.read()

# 읽어온 내용 출력
print(content)

'컴퓨터 > Python' 카테고리의 다른 글

Python pyinstaller  (1) 2023.12.04
Python tkinter  (0) 2023.12.04
Python Collections | 파이썬 콜렉션  (0) 2023.02.04
Python tuple | 파이썬 튜플  (0) 2023.02.01
Python max() | 파이썬 최대값  (0) 2023.02.01