상세 컨텐츠

본문 제목

파일 쓰기

python

by bumychoi 2024. 7. 5. 18:08

본문

# 파일 저장하기
#방법1
def write_alphabelt1(filepath):
    with open(filepath,"w") as file:
        for letter in "ABCDEFGHIJKLNMOPQRSTUVWXYZ":
            file.write(letter+" ")

print(f'ex1 결과:{write_alphabelt1("ex//23-1.txt")}')

 

 


#방법2
import string #빌트인 함수
def write_alphabelt2(filepath):
    with open(filepath,"w") as file:
        for letter in string.ascii_uppercase:
            file.write(letter+" ")

print(f"ex2 결과:{write_alphabelt2('ex//23-2txt')}")

'python' 카테고리의 다른 글

리스트 스플릿  (1) 2024.07.05
딕셔너리 생성  (0) 2024.07.05
파일에서 스플릿하기  (1) 2024.07.05
슬라이씽  (0) 2024.07.05
전역변수 & 지역변수  (0) 2024.07.05

관련글 더보기