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 = '
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__',
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
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