rep_word = 'The piece is gone, left the puzzle undone'

# \ 换行,跟shell一样
with open('nothing', 'r', encoding='utf-8') as f, \
    open('nothing1', 'w', encoding='utf-8') as f_new:
        for line in f:
            if rep_word in line:
                line = line.replace(rep_word, '碎片散去,留下已解的迷')
            f_new.write(line)


# 运行前 nothing
# Trying hard to fill the emptiness
# The piece is gone, left the puzzle undone
# Ain't that the way it is

# 运行后 nothing1
# Trying hard to fill the emptiness
# 碎片散去,留下已解的迷
# Ain't that the way it is

  

posted on 2018-04-28 10:50  PAYNE1Z  阅读(143)  评论(0)    收藏  举报