Revision 5145
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/csvs.py | ||
---|---|---|
38 | 38 |
|
39 | 39 |
class TsvReader: |
40 | 40 |
'''Unlike csv.reader, for TSVs, interprets \ as escaping a line ending but |
41 |
ignores it before everything else (e.g. \N for NULL). Also interprets the |
|
42 |
'\n' escape sequence as a newline.''' |
|
41 |
ignores it before everything else (e.g. \N for NULL). |
|
42 |
Also interprets '\n' as a newline and '\t' as a tab. |
|
43 |
''' |
|
43 | 44 |
def __init__(self, stream, dialect): |
44 | 45 |
assert is_tsv(dialect) |
45 | 46 |
self.stream = stream |
... | ... | |
64 | 65 |
record = record.replace('\r', ending_placeholder) |
65 | 66 |
|
66 | 67 |
row = csv.reader(StringIO.StringIO(record), self.dialect).next() |
67 |
return [v.replace(ending_placeholder, '\n') for v in row]
|
|
68 |
return [v.replace(r'\n', '\n').replace(r'\t', '\t') for v in row]
|
|
68 | 69 |
|
69 | 70 |
def reader_class(dialect): |
70 | 71 |
if is_tsv(dialect): return TsvReader |
Also available in: Unified diff
csvs.py: TsvReader: Also interpret '\t' as a tab, to provide a mechanism for encoding embedded tabs