Skip to content

Instantly share code, notes, and snippets.

@tobywf
Last active August 19, 2017 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobywf/bf48dd4210186ec8cf826f79a6ca66fa to your computer and use it in GitHub Desktop.
Save tobywf/bf48dd4210186ec8cf826f79a6ca66fa to your computer and use it in GitHub Desktop.
Generate CSV files with all permutations of common line endings
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
from itertools import product
import sys
try:
encoding = sys.argv[1]
except IndexError:
encoding = 'utf-8'
newlines = {
'\n': 'LF',
'\r': 'CR',
'\r\n': 'CR+LF',
}
for outer, inner in product(newlines.keys(), repeat=2):
description = inner.join([
'* This',
'* Is',
'* An',
'* Example',
])
data = outer.join([
'id,sku,description',
'100,AAAA,"{}"'.format(description),
'101,AAAB,🎅',
'102,AAAC,EOF',
])
# write binary to avoid any newline translation
with open('{}_{}.csv'.format(newlines[outer], newlines[inner]), 'wb') as fp:
fp.write(data.encode(encoding))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment