Python,来自字符串的模板,保存“bool”类型

2024-06-26 02:09:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用字符串模板,例如:

from string import Template

s = Template(u'(True, $type)')
res = s.substitute(type={'type': bool})
print res

输出:

(True, {'type': <type 'bool'>})

但是,我需要:

(True, {'type': bool})

我该怎么做?你知道吗


Tags: 字符串fromimport模板truestringtyperes