things like this. Confirmed with Python 3.7.2.
import string
#↓ This is ValueError:Invalid placeholder in string occurs
# template = string.Template('eng_key is${eng_key}is. Japanese key is${Japanese key}is')
template = string.Template('eng_key is${eng_key}is. Japanese key is${ja_key}is')
data = {
'eng_key': 'eng_hogehoge',
'Japanese key': 'ja_Hogehoge',
'ja_key': 'ja_hogehoge'
}
print(template.substitute(data))
# eng_key is eng_This is hogehoge. Japanese key is ja_hogehoge
Be careful if you have a Japanese key in your dict.
Recommended Posts