def replaceInFile(filename, oldToNew):
    """
    I replace the text `oldstr' with `newstr' in `filename' using science.
    """
    os.rename(filename, filename + '.bak')
    with open(filename + '.bak') as f:
        d = f.read()
    for k, v in oldToNew.items():
        d = d.replace(k, v)
    with open(filename + '.new', 'w') as f:
        f.write(d)
    os.rename(filename + '.new', filename)
    os.unlink(filename + '.bak')

    I replace the text `oldstr' with `newstr' in `filename' using science.
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/_release.py