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, but I need to make sure: for line in fileinput.FileInput("test_file.txt",inplace=1): > line = line.replace(original, new, 1) > > does this make more sense? On Sun, Jul 26, 2009 at 6:05 PM, Che M <pine...@hotmail.com> wrote: > > > 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 part of another word? > > > Essentially, I would like to replace only the occurrence that is > currently > > selected-- not the rest. for example: > > What do you mean by a word being "currently selected"? That phrase and > "scanning a text file" don't make sense to me together. How is the user > reading the text to select the word that is to be replaced? (Or maybe I am > not understanding something?) > > CM > > ------------------------------ > Bing™ brings you maps, menus, and reviews organized in one place. Try it > now.<http://www.bing.com/search?q=restaurants&form=MLOGEN&publ=WLHMTAG&crea=TXT_MLOGEN_Local_Local_Restaurants_1x1> > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor