[Tutor] why is unicode converted file double spaced?
Kent Johnson
kent37 at tds.net
Tue Apr 7 19:52:43 CEST 2009
On Tue, Apr 7, 2009 at 1:11 PM, Marc Tompkins <marc.tompkins at gmail.com> wrote:
> Anyway, try this -
>
>> import codecs
>>
>> inp = codecs.open('g:\\data\\amm\\text files\\test20090320.txt', 'r',
>> 'utf-16')
>> outp = open('g:\\data\\amm\\text files\\new_text_file.txt', 'w')
>>
>> for outLine in inp:
>> outp.write(outLine.strip())
>>
>> inp.close()
>> outp.close()
>
> strip() will remove any leading or trailing whitespace - which should
> include any leftover CR or LF characters.
You really should use rstrip(), leading white space is generally
significant in a text file, trailing white space not so much.
Kent
More information about the Tutor
mailing list