修改文件中的内容,使用fileinput模块

import fileinput

filename = 'passwd'

for line in fileinput.input(filename,inplace=1,backup='.bak')

    print line.replace('root','ROOT')

 

a = ' this is apple'
a.replace('this','that')

对字符串的替换

 

posted @ 2016-03-02 11:26  fengjian1585  阅读(325)  评论(0编辑  收藏  举报