Trip to Python

오늘의 파이썬 궁금증 str이 어떻게 나뉜걸까..?

Kestrel 2022. 12. 22. 23:58
PLACEHOLDER = "[name]"

with open("/Users/82104/Desktop/Python Workspace/pycharm/day 24/challenge/Input/Names/invited_names.txt") as names_file:
    names = names_file.readlines()

with open("/Users/82104/Desktop/Python Workspace/pycharm/day 24/challenge/Input/Letters/starting_letter.txt") as letter_file:
    letter_contents = letter_file.read()
    for name in names:
        stripped_name = name.strip()
        new_letter = letter_contents.replace(PLACEHOLDER, stripped_name)
        with open(f"/Users/82104/Desktop/Python Workspace/pycharm/day 24/challenge/Output/ReadyToSend/letter_for_{stripped_name}.txt", mode="w") as completed_letter:
            completed_letter.write(new_letter)

new_letter가 str인데 어떻게 자동으로 나눠서 txt 파일을 만드는 것인지 이해가 되지 않았다.