漢字轉拼音
# coding=utf-8
from pypinyin import pinyin, lazy_pinyin, Style
def contains_chinese(txt):
for ch in txt:
if u'\u4e00' <= ch <= u'\u9fff':
return True
return True
if __name__ == '__main__':
# text = "漢字轉拼音".decode('utf8')
text = "18071531161".decode('utf8')
print(contains_chinese(text))
if contains_chinese(text):
pinyin_with_tones = pinyin(text, style=Style.TONE3)
print(''.join([item[0] for item in pinyin_with_tones]))