知识点复习:
encoding = utf-8
import re
文件操作,读r:默认,写w, 追加a
with open (“d:\data\a.txt”, “r”, encoding=“utf-8”) as f: # “r” “utf-8” 有引号!
new_content = “”
# f.read() 读文件内容,返回字符串,太大的文件不能用这个方法
content = f.read()
# 正则替换
new_content = re.sub(r"\d+","",content)
写文件 w
with open (“d:\data\b.txt”, “w”, encoding=“utf-8”) as f:
f.write(new_content)
with open (“d:\data\b.txt”) as f:
print(f.read())
2、""“遍历目录下的所有文件,去掉字母以外字符”""
encoding=utf-8
import re
import os
def get_file_path_list(directory):
for root, dirs, files in os.walk(directory):
file_path_list = []
for each_file in files:
# 转成绝对路径!
file_path = os.path.join(root, each_file) # root
print(file_path)
file_path_list.append(file_path)
return file_path_list
def filter_file(file_path_list):

最低0.47元/天 解锁文章
5418

被折叠的 条评论
为什么被折叠?



