# -*- coding: utf-8 -*-
# @Time : 2022/11/2 11:22
# @Author : xxxd39
# @FileName: DelNUMstr.py
# @Software: PyCharm
# @Blog :https://blog.csdn.net/weixin_33595571?type=blog
import re
def del_number(string):
ls = []
for c in string:
ls += [c not in [str(i) for i in range(10)] and c or '']
return ''.join(ls)
# 获取file_path路径下的所有TXT文本内容和文件名
def get_text_list(file_path):
f = open(file_path, encoding='gbk')
return f.read()
print('请将要删除数字以及英文字符的文件保存为D:\\1.txt文件')
print('过滤完成后文件会保存为D:\\2.txt文件')
text_list = get_text_list('D:/1.txt')
print(text_list)
result = re.sub(u"([^\u4e00-\u9fa5\u0030-\u0039\u0041-\u005a\u0061-\u007a])", "", text_list)
chinese = ''.join(result)
strChinese = del_number(chinese)
print(strChinese)
path2 = r'D:\2.txt'
file2 = open(path2, 'w+')
file2.write(strChinese)
file2.close()
a = input('请输入任意字符开始:')
python txt文件去除数字字母只保留中文
最新推荐文章于 2024-07-17 02:19:30 发布