python : python基础===取txt文件的若干行到另一个文件

#取txt文件 的若干行到另一个txt
f1 = open(r'F:\movie.txt','rb')
f2= open(r'F:\movie2.txt','ab')

i=0
while True:
    line = f1.readline()
    i+=1
    if i>100 and i<150:
        f2.write(line)
    if i>200:
        break
#取txt文件 的若干行到另一个txt
f = open("./depth.txt",'rb')
f1 = open("./depth_1.txt",'ab')
f2 = open('./depth_2.txt','ab')
lines = f.readlines()

i=0

for n in lines :
    line = f.readline()
    i+=1
    if (i%2==0):
        f1.write(line)
    else :
        f2.write(line)

猜你喜欢

转载自blog.csdn.net/weixin_37251044/article/details/80389724