On Tue, Apr 14, 2015 at 7:48 AM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:
> with open(dfile, 'rb') as f:
> for line in f:
> try:
> s = line.decode('utf-8', 'strict')
> except UnicodeDecodeError as err:
> print(err)
>
> If you need h
On Tue, 14 Apr 2015 11:37 pm, Vincent Davis wrote:
>> Which DictReader? Do you mean the one in the csv module? I will assume
>> so.
>>
> yes.
>
>
>>
>> # untested
>> with open(dfile, 'r', encoding='utf-8', errors='ignore', newline='') as
>> f:
>> reader = csv.DictReader(f)
>> for row in
> Which DictReader? Do you mean the one in the csv module? I will assume so.
>
yes.
>
> # untested
> with open(dfile, 'r', encoding='utf-8', errors='ignore', newline='') as f:
> reader = csv.DictReader(f)
> for row in reader:
> print(row['fieldname'])
>
What you have seems to w
On Tue, 14 Apr 2015 10:54 pm, Vincent Davis wrote:
> I had been reading in a file like so. (python 3)
> with open(dfile, 'rb') as f:
> for line in f:
>
> line
> = line.decode('utf-8', 'ignore').split(',')
>
> How can I do accomplish decode('utf-8', 'ignore') when reading with
> DictReader
> How can I do accomplish decode('utf-8', 'ignore') when reading with
> DictReader()
Have you tried using the csv module in conjunction with codecs?
There shouldn't be any need to 'ignore' characters.
import csv
import codecs
rs = csv.DictReader(codecs.open(fn, "rbU", "utf8"))
I had been reading in a file like so. (python 3)
with open(dfile, 'rb') as f:
for line in f:
line
= line.decode('utf-8', 'ignore').split(',')
How can I do accomplish decode('utf-8', 'ignore') when reading with
DictReader()
Vincent Davis
720-301-3003
--
https://mail.python.org/mailman/