-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpinyin.py
33 lines (31 loc) · 1.08 KB
/
pinyin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pandas as pd
import pypinyin
trans1 = open('trans1.txt', encoding="utf8").read().split('\n')
trans2 = open('trans2.txt', encoding="utf8").read().split('\n')
trans3 = open('trans3.txt', encoding="utf8").read().split('\n')
trans4 = open('trans4.txt', encoding="utf8").read().split('\n')
trans5 = open('trans5.txt', encoding="utf8").read().split('\n')
trans6 = open('trans6.txt', encoding="utf8").read().split('\n')
trans = [trans1, trans2, trans3, trans4, trans5, trans6]
def pinyinit(file):
text = []
for combo in file:
print(combo)
a = combo.split(',')
list = pypinyin.pinyin(a[0])
pinyin = ''
for i in list:
pinyin += "".join(i)
print(pinyin)
b=combo+","+pinyin
text.append(b)
return text
# for i in range(0, 6):
# file = pinyinit(trans[i])
# with open(f'pinyin{i+1}.txt', 'w',encoding='utf8') as f:
# for item in file:
# f.write("\n%s" % item)
file = pinyinit(trans[4])
with open(f'pinyin{5}.txt', 'w',encoding='utf8') as f:
for item in file:
f.write("\n%s" % item)