Albert-Jan Roskam wrote:
Hi!
Did you consider using a regex?
import re
re.sub("python\s", "snake ", "python is cool, pythonprogramming...")
Cheers!!
Albert-Jan
--- On Mon, 7/27/09, Dave Angel wrote:
From: Dave Angel
Subject: Re: [Tutor] simple text re
Hi!
Did you consider using a regex?
import re
re.sub("python\s", "snake ", "python is cool, pythonprogramming...")
Cheers!!
Albert-Jan
--- On Mon, 7/27/09, Dave Angel wrote:
> From: Dave Angel
> Subject: Re: [Tutor] simple text replace
> To: &
j booth wrote:
Hello,
I am scanning a text file and replacing words with alternatives. My
difficulty is that all occurrences are replaced (even if they are part of
another word!)..
This is an example of what I have been using:
for line in fileinput.FileInput("test_file.txt",inplace=1):
oops, I mean that the script opens a file and splits it into words; Then it
takes each word and searches for an alternative online; with the alternative
now stored in a variable, it simply needs to be written back over the
original word in the same file.
at the moment this might solve the problem,
> I am scanning a text file and replacing words with alternatives. My
> difficulty
> is that all occurrences are replaced (even if they are part of another
> word!)..
Could you search for the string ' word ' with the white spaces around it?
Shouldn't
that only replace words that are not par
Hello,
I am scanning a text file and replacing words with alternatives. My
difficulty is that all occurrences are replaced (even if they are part of
another word!)..
This is an example of what I have been using:
for line in fileinput.FileInput("test_file.txt",inplace=1):
> line = lin