利用python读取txt文件里数据的分号;改成空格

利用python把txt文件里数据的分号;改成空格 

import os

source_path = './txt'
target_path = './result'

if not os.path.exists(target_path):
    os.mkdir(target_path)

file_list = os.listdir(source_path)

for file in file_list:
    full_sou = os.path.join(source_path, file)
    full_tar = os.path.join(target_path, file)

    print("process:", full_sou)
    
    with open(full_sou, 'r') as f:
        context = f.readlines()
        context = list(map(lambda x: x.replace(';',' '),context))
    with open(full_tar, 'w') as f:
        f.writelines(context)

 

posted @ 2020-05-31 13:18  这不是粥  阅读(1326)  评论(0编辑  收藏  举报