Skip to content

Instantly share code, notes, and snippets.

@oryband
Created October 6, 2014 14:56
Show Gist options
  • Save oryband/d284df0f93e68a4e33e9 to your computer and use it in GitHub Desktop.
Save oryband/d284df0f93e68a4e33e9 to your computer and use it in GitHub Desktop.
Copy & replace text from input file to output file.
#!/usr/bin/env python
"""Copy & replace text from INPUT_PATH to OUTPUT_PATH."""
# Consts
REPLACE = ('\n', ' ', '\t')
REPLACE_WITH = (',')
INPUT_PATH = 'path/to/input.txt'
OUTPUT_PATH = 'path/to/output.txt'
if __name__ == '__main__':
with open(INPUT_PATH, 'rb') as input, open(OUTPUT_PATH, 'wb') as output:
data = input.read()
for char in REPLACE:
if char in data:
data = data.replace(char, REPLACE_WITH)
output.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment