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 = line.replace(original, new)
>         print line,
>         fileinput.close()


original and new are variables that have string values from functions..
original finds each word in a text file and old is a manipulated
replacement. Essentially, I would like to replace only the occurrence that
is currently selected-- not the rest. for example:

python is great, but my python knowledge is limited! regardless, I enjoy
> pythonprogramming


returns something like:

snake is great, but my snake knowledge is limited! regardless, I enjoy
> snakeprogramming


thanks so much!
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to