python

파일 쓰기

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')}")