python A.txt一行一行读取文件,分割这行取倒数一个数据,之后保存B.txt, 每行A.txt已操作后B.txt对应
比方:A.txt内容2016-06-3023:38<DIR>..2016-05-0419:07854,485,71412.Monkeys.S02E02.720p.HDTV...
比方:A.txt内容
2016-06-30 23:38 <DIR> ..
2016-05-04 19:07 854,485,714 12.Monkeys.S02E02.720p.HDTV.x264-AVS.mkv
2016-05-04 18:24 885,362,520 12.Monkeys.S02E03.720p.HDTV.x264-KILLERS.mkv
最后结果B.txt
..
12.Monkeys.S02E02.720p.HDTV.x264-AVS.mkv
12.Monkeys.S02E03.720p.HDTV.x264-KILLERS.mkv
======
目前我只会单独操作一个行,不会读取文件操作
import re
str = "2016-05-04 19:07 854,485,714 12.Monkeys.S02E02.720p.HDTV.x264-AVS.mkv"
ls=str.split(" ")[-1]
print (ls) 展开
2016-06-30 23:38 <DIR> ..
2016-05-04 19:07 854,485,714 12.Monkeys.S02E02.720p.HDTV.x264-AVS.mkv
2016-05-04 18:24 885,362,520 12.Monkeys.S02E03.720p.HDTV.x264-KILLERS.mkv
最后结果B.txt
..
12.Monkeys.S02E02.720p.HDTV.x264-AVS.mkv
12.Monkeys.S02E03.720p.HDTV.x264-KILLERS.mkv
======
目前我只会单独操作一个行,不会读取文件操作
import re
str = "2016-05-04 19:07 854,485,714 12.Monkeys.S02E02.720p.HDTV.x264-AVS.mkv"
ls=str.split(" ")[-1]
print (ls) 展开
展开全部
将A.txt,以空格为分隔符,每行最后一个数据读出,写到B.txt中
#-*- coding: UTF-8 -*-
import re
import sys
import os
str=[]
fa=open("A.txt",'r')
for line in fa.readlines():
print line
str1=line.split(" ")[-1]
print str1
str.append(str1)
fb=open("B.txt",'a')
for i in str:
fb.write(i)
fa.close()
fb.close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询