Re: Find and replace in a file with regular expression

2007-02-03 Thread Frederic Rentsch
TOXiC wrote: > Hi everyone, > First I say that I serched and tryed everything but I cannot figure > out how I can do it. > I want to open a a file (not necessary a txt) and find and replace a > string. > I can do it with: > > import fileinput, string, sys > fileQuery = "Text.txt" > sourceText = '

Re: Find and replace in a file with regular expression

2007-01-31 Thread Wolfgang Grafen
Just in case you didn't think about it there is a plain replace method for strings How to quick-search this method with 'dir' >>> dir("") ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__',

Re: Find and replace in a file with regular expression

2007-01-30 Thread Matimus
The re module is used for regular expressions. Something like this should work (untested): import fileinput, string, sys, re fileQuery = "Text.txt" sourceText = '''SOURCE''' replaceText = '''REPLACE''' def replace(fileName, sourceText, replaceText): file = open(fileName, "r") tex

Find and replace in a file with regular expression

2007-01-30 Thread TOXiC
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it with: import fileinput, string, sys fileQuery = "Text.txt" sourceText = '''SOURCE''' replaceText = '''REP