import fileinput filename = 'passwd' for line in fileinput.input(filename,inplace=,backup='.bak') print line.replace('root','ROOT')
a = ' this is apple'
a.replace('this','that') 对字符串的替换
import fileinput filename = 'passwd' for line in fileinput.input(filename,inplace=,backup='.bak') print line.replace('root','ROOT')
a = ' this is apple'
a.replace('this','that') 对字符串的替换