Let's say I have this textfile: date.txt. month|day|year
January|20|2014
February|10|
March|5|2013
I want to put 2012 after February|10|. how can i do that?
Let's say I have this textfile: date.txt. month|day|year
January|20|2014
February|10|
March|5|2013
I want to put 2012 after February|10|. how can i do that?
You need to read the file into memory, modify the desired line and write back the file.
If you don't want to use a temporary file:
You can use the
csv
module, for example:Please note:
csv.reader()
take as argument any iterable object. So, you can easily pass it a file object