Re: [Tutor] simple text replace

2009-07-27 Thread Dave Angel
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

Re: [Tutor] simple text replace

2009-07-27 Thread Albert-Jan Roskam
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: &

Re: [Tutor] simple text replace

2009-07-26 Thread Dave Angel
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):

Re: [Tutor] simple text replace

2009-07-26 Thread j booth
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,

Re: [Tutor] simple text replace

2009-07-26 Thread Che M
> 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

[Tutor] simple text replace

2009-07-26 Thread j booth
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