制造规定行数的数据文件

with open('C:/Users/lhd/Desktop/many/C1_BYXJ_20181209_001.txt', 'r', encoding='utf-8') as file:
    num = 0
    data = file.readlines() #  这样出来是一个大的列表,还带有分隔符
    print(type(data))
    for i in data: # 遍历这个列表
        num +=1
        if num==2000:
            break
        else:
            # re = i.replace('\n','')# 这样会把换行符替换成无
            with open('C:/Users/lhd/Desktop/many/a.txt', 'a', encoding='utf-8') as a:
                a.write(i)

你可能感兴趣的:(制造规定行数的数据文件)