Skip to content

Instantly share code, notes, and snippets.

@mitake
Last active December 11, 2015 12:49
Show Gist options
  • Save mitake/4603184 to your computer and use it in GitHub Desktop.
Save mitake/4603184 to your computer and use it in GitHub Desktop.
string replace in python
#! /usr/bin/env python
import sys, re
def conf_file(path):
f = open(path, 'r')
res = []
for line in f.readlines():
line = line.replace('vprintf', 'sd_printf')
line = line.replace('eprintf', 'sd_eprintf')
line = line.replace('dprintf', 'sd_dprintf')
res.append(line)
f.close()
f = open(path, 'w')
for line in res:
f.write(line)
for path in sys.stdin.readlines():
conf_file(path.rstrip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment