# sed workaround, shamelessly stolen & modified # from https://raw.githubusercontent.com/mahmoudadel2/pysed/master/pysed.py def replace(oldstr, newstr, infile): linelist = [] with open(infile) as f: for item in f: newitem = re.sub(oldstr, newstr, item) linelist.append(newitem) with open(infile, "w") as f: f.truncate() for line in linelist: f.writelines(line)