하지만 이 기능도 앞에서 설명한 네 번째 문제점인 키가 반복되는 경우의 중복을 줄여주지는 못한다. 예를 들어 C 스타일의 형식화 식과 format 메서드에 키워드 인자를 넘기는 새로운 스타일의 형식화를 비교해보자.

    old_template = (
        'Today\'s soup is %(soup)s, '
        'buy one get two %(oyster)s oysters, '
        'and our special entrée is %(special)s.')
    old_formatted = template % {
        'soup': 'lentil',
        'oyster': 'tongyoung',
        'special': 'schnitzel',
    }
    
    new_template = (
        'Today\'s soup is {soup}, '
        'buy one get two {oyster} oysters, '
        'and our special entrée is {special}.')
    new_formatted = new_template.format(
        soup='lentil',
        oyster=' tongyoung',
        special='schnitzel',
    )
    
    assert old_formatted == new_formatted
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.