python - Is it possible to modify lines in a file in-place? -


Is it possible to parse a file line through a line, and it is possible to edit a line in in-play ?

Is it possible to parse a file line through a line, and at the same time Is it possible to edit lines through?

This can be simulated as a stdlib using a backup file.

Here is an example script that can be copied from files given on any_condition command line or stdin :

  #! Import file input for line in / usr / bin / env python # grep_some_condition.py file input. Input (inplace = true, backup = '. Bak'): If some codification (line): print line, this current file   

example:

  $ Python grep_some_condition.py first_file.txt second_file.txt   

on completion first_file.txt and second_file.txt files only rows th Include some_condition () predicate satisfied.

Comments