#!/usr/bin/env python
‘‘‘Replace oldfile‘s char ‘wang‘ to char ‘yuan‘
replace char ‘wang‘ to char ‘yuan‘,and write
the changed file into ‘newfile‘
in production environment
replace the keychars following:
oldfile wang yuan newfile
‘‘‘
oldfile = raw_input(‘which file do you want to replace: ‘)
newfile = raw_input(‘Enter a name for new file: ‘)
oldchar = raw_input(‘which character do you wang to replace: ‘)
newchar = raw_input(‘Enter the New character: ‘)
for line in open(‘%s‘ % oldfile):
open(‘%s‘ % newfile,‘a‘).write(line.replace(‘%s‘ % oldchar,‘%s‘ % newchar))
时间: 2024-10-30 15:20:01