[Csv] CSV ignores lineterminator

Andrew McNamara andrewm at object-craft.com.au
Tue Apr 6 01:35:28 CEST 2004


>With
> 
> input_data = ['word1\tword2;word3\tword4;',
> 'word5\tword6;word7\tword8;']
> 
> and
> 
> delimiter = '\t'
> lineterminator = ';'
> 
> shouldn't csv.reader(input_data, dialect='mydialect') return
> 
> ['word1', 'word2']
> ['word3', 'word4']
> ['word5', 'word6']
> ['word7', 'word8']
> 
> I find that it doesn't matter how I set lineterminator, csv always 
>terminates at the end of the line returned by the iterable object passed
>as its first argument (input_data, in this case):
> 
> word1 word2;word3 word4
> word5 word6;word7 word8

Yes - the lineterminator is only used for output. When the csv module was
moved to 2.3, we chose to implement the iterator protocol for input so the
module could accept input from any iterator-like object.  Unfortunately,
this also introduces the inconsistency you have noted.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


More information about the Csv mailing list