import shutil
src_dir:源文件夹
dst_dir:目标文件夹
for filename in os.listdir(src_dir): shutil.move(os.path.join(src_dir, filename), dst_dir)
filename:文件名
encoding:文件编码
with open(filename, encoding=encoding) as f: lines = f.readlines()
reversed_lines = [line[::-1] for line in lines]
new_filename:新文件名
with open(new_filename, 'w', encoding=encoding) as f: f.writelines(reversed_lines)
filename:文件名
encoding:文件编码
with open(filename, encoding=encoding) as f: lines = f.readlines()
upper_lines = [line.upper() for line in lines]
new_filename:新文件名
with open(new_filename, 'w', encoding=encoding) as f: f.writelines(upper_lines)
filename:文件名
encoding:文件编码
delimiter:分隔符
with open(filename, encoding=encoding) as f: lines = f.readlines()
fields_list = [line.split(delimiter) for line in lines]
new_filename:新文件名
with open(new_filename, 'w', encoding=encoding) as f: f.writelines(fields_list)
filename:文件名
encoding:文件编码
old_str:旧字符串
new_str:新字符串
with open(filename, encoding=encoding) as f: lines = f.readlines()
replaced_lines = [line.replace(old_str, new_str) for line in lines]
new_filename:新文件名
with open(new_filename, 'w', encoding=encoding) as f: f.writelines(replaced_lines)
本文链接:http://task.lmcjl.com/news/8506.html