保存: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})
どうすればいいですか?
まあ、 'bool'はPythonで呼び出し可能な組み込みであるので、あなただけの文字列を渡す試してみました...オブジェクトのですか? 'type = 'bool''? –
はい、私は自分の質問を編集しました。 {type ':' bool '} – Artem
私は文字通り '.subtitute(type =' bool ')'を意味していました。その時点でそれをやっています... –