Finding Blank Columns in CSV
Jaydip Chakrabarty
chalao.adda at gmail.com
Tue Oct 6 23:02:07 EDT 2015
On Tue, 06 Oct 2015 19:25:12 +0100, MRAB wrote:
> On 2015-10-06 18:23, Jaydip Chakrabarty wrote:
>> On Tue, 06 Oct 2015 14:33:51 +0200, Peter Otten wrote:
>>
> [snip]
>>
>> I downloaded gmail contacts in google csv format. There are so many
>> columns. So I was trying to create another csv with the required
>> columns.
>> Now when I tried to open the gmail csv file with csv DictReader, it
>> said the file contained NULL characters.
>
> Why would there be nulls in a CSV file?
>
>> So first I did -
>>
>> data = open(fn, 'rb').read()
>> fout = open(ofn, 'wb')
>> fout.write(data.replace('\x00', ''))
>> fout.close()
>> shutil.move(ofn, fn)
>>
>> Then I found, there were some special characters in the file. So, once
>> again I opened the file and did -
>>
>> data = open(fn, 'rb').read()
>> fout = open(ofn, 'wb')
>> fout.write(data.replace('\xff\xfe', ''))
>> fout.close()
>> shutil.move(ofn, fn)
>>
> b'\xff\xfe' looks like a BOM.
>
> If it's at the start of the file, it indicates that the file is encoded
> in 'UTF16-LE'.
>
> So, apparently, the original file was CSV encoded in 'UTF16-LE'.
>
> You _do_ still have the original file, don't you?
>
> [snip]
Yes, I am having it.
Thanks.
More information about the Python-list
mailing list