[Memorandum] Japanese keys cannot be used in python string.Template.substitute

What kind of mess

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

[Memorandum] Japanese keys cannot be used in python string.Template.substitute
Japanese can be used with Python in Docker environment
list comprehension because operator.methodcaller cannot be used in python 2.5
Operators ++,-cannot be used in python (difference from php)
[Redash] Standard library cannot be used in python function
Japanese output in Python
Python note: When the pip command cannot be used
Can be used in competition pros! Python standard library
I wrote python in Japanese
I understand Python in Japanese!
Get Japanese synonyms in Python
Video cannot be loaded with Spyder in Python development environment
Scripts that can be used when using bottle in Python
8 Frequently Used Commands in Python Django
[Python] It seems that global variables cannot be referenced in Multiprocessing
[Python] Basic knowledge used in AtCoder
33 strings that should not be used as variable names in python
Investigating what could be used as a Markdown parser in Python
New features in Python 3.9 (1)-Union operators can be used in dictionary types
Python standard input summary that can be used in competition pro
Jupyter Notebook 6.0.2 cannot be installed in the Python 2.7 environment created in Anaconda
[Python] Do not put Japanese in the path used by OpenCV
How to handle Japanese in Python
Modules cannot be imported in Python on EC2 run from AWS Lambda
I tried to put PyCharm in Ubuntu 16.04 LTS (PPA cannot be used)
When specifying multiple keys in python sort
Comparison of Japanese conversion module in Python3
[python] Frequently used techniques in machine learning
Python modules with "-(hyphen)" cannot be removed
Tkinter could not be imported in Python
Python memorandum
A solution to the problem that the Python version in Conda cannot be changed
Python Memorandum 2
I made a familiar function that can be used in statistics with Python
Let's look at a differential equation that cannot be solved normally in Python
Python memorandum
python memorandum
python memorandum
Python memorandum
python memorandum
Correspondence memo when the direction key cannot be used on the python command line
Python memorandum
De-VBA Excel tool! Eliminate VBA tool with Python in environment where Python cannot be installed
List of tools that can be used to easily try sentiment analysis of Japanese sentences in Python (try with google colab)
Functions that can be used in for statements
"Temporary solution" when pip cannot be updated [Python]
Techniques often used in python short coding (Notepad)
Resolve Japanese write error UnicodeEncodeError in Python files
Get multiple maximum keys in Python dictionary type
Python environment settings (virtualenv + pip cannot be done)
No module named'distutils.util' cannot be used with get-pip.py
Handle zip files with Japanese filenames in Python 3
Investigation when import cannot be done with python
Create an image with characters in python (Japanese)
[Python] f strings should be used for embedding strings
Code often used in Python / Django apps [prefectures]
[Python] Which should be used, return or return None
[Django] css in the project cannot be read
Standard .py file used in Python trials (template)-2020
Matplotlib etc. cannot be imported in VirtualEnv environment
The problem that the ifconfig command cannot be used