#!/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 keywords 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-17 16:22:09