I am a beginner with python and I want to do this: Read in a text file, manipulate the text in some way and then write out another text file. Now, so far, to get the framework of the code going, I have this.
- Code: Select all
filename = "....../inputParser.txt"
f_in = open(filename, 'r')
f_out = open("outputParser.txt",'w')
text = f_in.read()
Now, do you have any recommendations as to how I should go about replacing dotted lines above with something more complicated that manipulates the text from an input file? For instance, 1. replace every occurrence of 'abc' by 'cba' and keep doing so if another abc is formed during this replacement; 2. Access some nth word in a comma separated line, 3. Delete any line starting with a # etc; just any kind of text modification. How do I do all such stuff using python? Something in particular that I should read?
Thank you for your help.