Replace the whole string if it contains specific letters/character

Replace the whole string if it contains specific letters/character…

I have a text file (myFile.txt) that contains multiple lines, for example:

The hotdog
The goal
The goat

What I want to do is the following:

If any word/string in the file contains the characters 'go' then, replace it with a brand new word/string ("boat"), so the output would look like this:

The hotdog
The boat
The boat

How can I accomplish this in Python 2.7?

链接地址: http://www.djcxy.com/p/55078.html

上一篇: 更改导入模块的变量似乎不起作用。 [蟒蛇]

下一篇: 如果它包含特定的字母/字符,则替换整个字符串