|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>>> template = '''<html>
<head><title>{title}</title></head>
<body>
<h1>{title}</h1>
<p>{text}</p>
</body>'''
>>> date = {'title':'My Home Page', 'text':'Welcome to my home page!'}
>>> print(template.format(date))
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
print(template.format(date))
KeyError: 'title'
>>> print(template.format_map(date))
<html>
<head><title>My Home Page</title></head>
<body>
<h1>My Home Page</h1>
<p>Welcome to my home page!</p>
</body>
用format为什么错误了 |
|