1 打开日志文件

虽然,日志文件的后缀为.log,但是基本上与文本文件没有区别,按照一般读取文本文件的方式打开即可:

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

应用示例:

fp =open("e:\\data.log")
for line in fp.readlines(): # 遍历每一行
    filename = line[:14]    # 每行取前14个字母,作为下面新建文件的名称
    content = line[14:]     # 每行取第15个字符后的所有字符,作为新建文件的内容
 
    with open("e:\\"+filename+".txt","w") as fp2:
        fp2.write(content+"\n")
 
fp.close()
View Code

相关文章:

  • 2021-04-17
  • 2021-04-14
  • 2022-12-23
  • 2021-09-24
  • 2021-06-16
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案