Skip to content

Commit 9fab572

Browse files
committed
submit code
submit code
1 parent 014405f commit 9fab572

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

chaoxi/work_pro/cac_txt.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#coding:utf-8
2+
import re
3+
#读取目标文本文件
4+
def get_str(path):
5+
f = open(path)
6+
data = f.read()
7+
f.close()
8+
return data
9+
# 输入目标路径
10+
path=input("请输入文件路径:")
11+
12+
word=re.findall('([\u4e00-\u9fa5])',get_str(path))
13+
14+
# 计算出特殊字符外的字数
15+
print("中文字符,除特殊字符外共:",len(word))

chaoxi/work_pro/phone_excel.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#coding:utf-8
2+
import xlwt
3+
4+
#读取目标文本文件
5+
def get_str(path):
6+
f = open(path, encoding="utf-8")
7+
data = f.read()
8+
f.close()
9+
return data
10+
11+
12+
def save_excel(save_path,sheetname,column_name_list,read_list):
13+
workbook = xlwt.Workbook()
14+
15+
sheet1 = workbook.add_sheet(sheetname=sheetname)
16+
17+
for i in range(0,len(column_name_list)):
18+
sheet1.write(0,i,column_name_list[i])
19+
i = 1
20+
for v in read_list:
21+
kval = v.split(':')
22+
for j in range(0, len(kval)):
23+
sheet1.write(i + 1, j, kval[j])
24+
print(kval[j])
25+
i = i + 1
26+
#保存为Excel文件
27+
def save_excel(save_path,sheetname,column_name_list,read_list):
28+
workbook = xlwt.Workbook()
29+
sheet1 = workbook.add_sheet(sheetname=sheetname)
30+
for i in range(0,len(column_name_list)):
31+
sheet1.write(0,i,column_name_list[i])
32+
i=1
33+
for v in read_list:
34+
kval=v.split(':')
35+
for j in range(0,len(kval)):
36+
sheet1.write(i+1,j,kval[j])
37+
i=i+1
38+
workbook.save(save_path)
39+
print('信息保存 OK,记录条数共计:'+str(len(read_list)))
40+
41+
if __name__ == '__main__':
42+
path = input("请输入文件路径:")
43+
save_path = input("请输入文件保存路径:")
44+
sheet_name = input("请输入sheetname:")
45+
column_name = input("请输入列名,并且使用英文逗号隔开:")
46+
column_name_list = column_name.split(',')
47+
48+
read_str = get_str(path)
49+
read_list = read_str.split('\n')
50+
save_excel(save_path, sheet_name, column_name_list, read_list)

chaoxi/work_pro/phone_txt.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import re
2+
3+
#读取目标文本文件
4+
def get_str(path):
5+
f = open(path,encoding="utf-8")
6+
data = f.read()
7+
f.close()
8+
return data
9+
10+
# 正则获取文本号码
11+
def get_phone_number(str):
12+
res = re.findall(r'(13\d{9}|14[5|7]\d{8}|15\d{9}|166{\d{8}|17[3|6|7]{\d{8}|18\d{9})', str)
13+
return res
14+
15+
#保存得到号码
16+
def save_res(res,save_path):
17+
save_file = open(save_path, 'w')
18+
for phone in res:
19+
save_file.write(phone)
20+
save_file.write('\n')
21+
save_file.write('\n号码共计:'+str(len(res)))
22+
save_file.close()
23+
print('号码读取OK,号码共计:'+str(len(res)))
24+
25+
if __name__ == '__main__':
26+
path=input("请输入文件路径:")
27+
save_path=input("请输入文件保存路径:")
28+
#read_str=get_str(path)
29+
res=get_phone_number(get_str(path))
30+
save_res(res,save_path)

0 commit comments

Comments
 (0)