23.处理数据文件.

数据分析需求: 每行内容需要生成以每行 首年月日为名称的文件, 文件内容写入|0|后的所有 行内容(也包括|0|

算法分析: Ø遍历每一行,每行取头14个字母 Ø

新建文件,文件名为首14个字母,然后把第15字符后的所有字 符拷贝到文件中 Ø

关闭文件

fp =open("e:\\data.log")

for line in fp.readlines():

    filename = line[:14]

    content = line[14:]

    with open("e:\\"+filename+".txt","w") as fp2:

        fp2.write(content+"\n")

fp.close()

猜你喜欢

转载自www.cnblogs.com/luo25236240/p/9264854.html
今日推荐