Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97455 > unrolled thread

Re: Finding Blank Columns in CSV

Started byMRAB <python@mrabarnett.plus.com>
First post2015-10-06 19:25 +0100
Last post2015-10-06 19:25 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Finding Blank Columns in CSV MRAB <python@mrabarnett.plus.com> - 2015-10-06 19:25 +0100

#97455 — Re: Finding Blank Columns in CSV

FromMRAB <python@mrabarnett.plus.com>
Date2015-10-06 19:25 +0100
SubjectRe: Finding Blank Columns in CSV
Message-ID<mailman.433.1444155917.28679.python-list@python.org>
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]

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web