python批量读取txt文本,处理,并批量保存

python批量读取txt文本,处理,并批量保存_第1张图片

比如我们有如下的txt文本数据,我们该如何读取呢。

import os
import time

path = './txt_9000/' # txt文件路径
files= os.listdir(path)
files.sort()

for file in files:
    with open(path + file, 'r',encoding='utf-8') as f:
        numbers= f.readlines()
        print(numbers)
        for i in range(len(numbers)):
            txt = numbers[i]
            print(txt)

    time.sleep(20)

看一下读取的结果:

['88.82,98.33,98.82,191.42,456.95,184.42,447.95,99.33,薄利汽配\n', '30.91,20.4,26.91,44.2,343.85,45.2,345.85,21.4,五菱荣光前外拉
手颜色齐全\n']
88.82,98.33,98.82,191.42,456.95,184.42,447.95,99.33,薄利汽配

30.91,20.4,26.91,44.2,343.85,45.2,345.85,21.4,五菱荣光前外拉手颜色齐全

你可能感兴趣的:(python实用教程,python,开发语言,后端)