본문 바로가기

카테고리 없음

Python Template

import string

from pprint import pprint 

import uuid

# p = {'name': 'John', 'age': 21}

# tpl = string.Template('''

#     name: $name

#     age: $age - ${age}s

# ''')

# n = tpl.substitute(p)

# print(n)


k =[ {'name': 'John', 'link': 'http:///recv', 'uuid':uuid.uuid4(), 'attach':None},

        {'name': 'Cirrus', 'link': 'http:///recv', 'uuid':'aaaaaa-bbbbbb-ccccc','attach':None}]


template_html_body = '''

<a href="#">

    Link: $link/$uuid

    name: ${name}s

    attachment: $attach

</a>

'''

tpl = string.Template(template_html_body)


for p in k:

    result = tpl.substitute(p)

    print(result)