First, the original intention:
Some of the open source software configuration files identified in the section in English, then we in the bulk generation of configuration files, we can import Chinese characters from the CMDB (Idc_name),
Then convert it to pinyin, or splice the IP address for more accurate identification. For example: Smokeping's targets configuration file, as follows:
+== telcom++yunfuxinxingshuangxian-01-61= Yunfu Emerging Dual line -01= 61.11.11.11 = 61.11.11.11
Second, the method:
We can call Python's pypinyin library to solve the problem of Chinese characters turning into pinyin.
>>>ImportPypinyin>>> fromPypinyinImportPinyin, Lazy_pinyin>>> Lazy_pinyin (U'Yunfu xinxing double line -01') [u'Yun', u'Fu', u'Xin'+ R'Xing'+ R'Shuang'+ R'Xian'+ R'-01']>>>"'. Join (Lazy_pinyin (U'Yunfu xinxing double line -01')) U'yunfuxinxingshuangxian-01'>>>"'. Join (Lazy_pinyin (U'Yunfu xinxing double line -01'))+'-'+'61.11.11.11'. Split ('.') [0]u'yunfuxinxingshuangxian-01-61'
In addition: You turn the kanji into Pinyin to write the configuration file, may also need to convert pinyin into Chinese characters, used to display reports and so on.
Then you can read the configuration file and take the corresponding menu (Kanji section). There is only one way to solve the problem, specifically to see the actual needs.
' {print $NF}
Attached: Chinese Pinyin conversion tool (Python version) official website: http://pypinyin.readthedocs.org/en/master/
Python kanji to Pinyin library Pypinyin