Skip to content

Instantly share code, notes, and snippets.

View rqelibari's full-sized avatar

Rezart Qelibari rqelibari

  • Germany
  • 10:30 (UTC +02:00)
View GitHub Profile
@rqelibari
rqelibari / replace_string_in_file.py
Last active December 23, 2017 16:18
Python >2.7 function to replace a string in a file using mmap.
#!/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.