利用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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM