Python kanji to Pinyin library Pypinyin

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.