Python: 字符串格式化时未全部转换参数
import datetime
now = datetime.date.today()
now = str(now)
index = open('/var/www/index.html', 'a')
index.write('<br> $s,' %now)
index.close()
我一直收到这个错误。
2 个回答
1
index.write('<br> {now},'.format(now=now))
.format
比 string-formatting
好得多,具体可以参考 这个链接
2
你需要使用正确的格式:
index.write('<br> %s,' %now)
应该是 %s
,而不是 $s
。