Skip to content

Instantly share code, notes, and snippets.

@kipanshi
Created January 24, 2012 22:04
Show Gist options
  • Save kipanshi/1672996 to your computer and use it in GitHub Desktop.
Save kipanshi/1672996 to your computer and use it in GitHub Desktop.
Reduce + Replace
REPLACE_MAP = (
('project_dir', project_dir),
('user', user)
)
TEMPLATE = '{{ %s }}'
for line in source.readlines():
dest.write(
reduce(
lambda x, y: x.replace(TEMPLATE % y[0], y[1]),
(line,) + REPLACE_MAP
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment