Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to write to a specific line in a file python

with open('input') as fin, open('output','w') as fout:
    for line in fin:
        fout.write(line)
        if line == 'xxxxx
':
           next_line = next(fin)
           if next_line == 'yyyyy
':
              fout.write('my_line
')
           fout.write(next_line)
           
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #write #specific #line #file #python
ADD COMMENT
Topic
Name
2+2 =