Modify the operation of the document

Modify the operation of the document

#_author: Administrator 
#date: 2019/10/31
# modify the file
# (1) is added after the sixth row
# = f_read Open ( 'LL', 'R & lt', encoding = 'UTF8')
# = f_write Open ( ' LL1 ',' W ', encoding =' UTF8 ')
# Number = 0
# Line for in f_read:
# = Number. 1 +
# IF. 6 == Number:
# Line ='. 'the Join ([line.strip (),' zialushang \ the n-'])
# f_write.write (Line) # () must be passed within the parameter Line
# f_write.close ()
# f_read.close ()
# lead vintage wine
# choking quite tasty
# how tears also fall occasionally invite you to take a closer look hearts gap
# cracks retained gentle
# this time the birds are flying long grass
# loved one is on the way zialushang
# I know his trials and hardships
# Higurashi not passing through the crowd just to reward you with embracing
# (2) replacing the sixth row
# f_read = open ( 'll' , 'r', encoding = 'utf8 ')
# f_write=open('ll2','w',encoding='utf8')
# number=0
# for line in f_read:
# number+=1
# if number==6:
# line='hello star\n'
# f_write.write(line)#()内一定要传参数line
# f_write.close()
# f_read.close()
#2.使用with不用使用close方法关闭文件
#with同时管理多个文件对象
number=0
with open('ll','r',encoding='utf8') as f_read,open('ll3','w',encoding='utf8') as f_write:
for line in f_read:
number+=1
if number==6:
line=''.join([line.strip(),'statstar\n'])
f_write.write(line)
Output:
<1>
Lead vintage wine 
choking quite tasty
how the tears still fall occasionally invite you to take a closer look mind the gap
cracks retained tender
this time the birds are flying long grass
loved one is on the way statstar
I know his trials and hardships
passing through Higurashi no reward people sea just to be with you embracing

<2>
Lead vintage wine 
choking quite tasty
how the tears still fall occasionally invite you to take a closer look mind the gap
cracks retained tender
this time the birds are flying long grass
statstar
I know his trials and hardships
via Higurashi no reward through the crowd just to be with you embracing

Guess you like

Origin www.cnblogs.com/startl/p/11769906.html