Skip to content

Instantly share code, notes, and snippets.

Avatar

Rezart Qelibari rqelibari

View GitHub Profile
@rqelibari
rqelibari / replace_string_in_file.py
Last active Dec 23, 2017
Python >2.7 function to replace a string in a file using mmap.
View replace_string_in_file.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (unicode_literals,
with_statement)
import mmap
import os.path
def replace_placeholder_in_file(filepath, placeholder, text):
"""Replace `placeholder` in file `filename` with `text` if found.