Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV Reader
#1
Hi

I am a new programmer with Python and do appreciate any help or suggestions - a virtual beer is offered :)

I am running my program and get this error - 

Error:
Traceback (most recent call last):   File "C:\SFF\Code\SFF_Analyzer.py", line 229, in <module>     for row in reader:   File "C:\Program Files\Python35\lib\encodings\cp1252.py", line 23, in decode     return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 5582: character maps to <undefined>
My code is 

with open(prodfile, "r") as f_product:
     reader = csv.reader(f_product,delimiter=',')
     
     for row in reader:
         prod_list.append(row[0]) # we now have a Product list stored TAG 
         prod_1.append(row[2])  # we now have a Mono Cube list stored LONG DESCRIPTION
         prod_2.append(row[4])  # we now have a Mono Cube list stored PARENT TAG
         prod_3.append(row[6])  # we now have a Mono Cube list stored HIER NAME
         prod_4.append(row[7])  # we now have a Mono Cube list stored HIER LEVEL NUMBER
         prod_5.append(row[8])  # we now have a Mono Cube list stored HIER LEVEL NAME
         prodcount = prodcount + 1
         s.add(row[0]) # create a set 
I see in my data I have a Tilda char ~~~~~~~~~~~~~  so i think this may be the issue but i am not sure -any help is appreciated and im on PYTHON 3.5.3

Regards

Chris
Reply
#2
Try:
with open(prodfile, "r") as f_product:
# To
with open(prodfile, encoding='utf-8') as f_product:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  xml simple reader kucingkembar 2 1,022 Aug-19-2022, 08:51 PM
Last Post: kucingkembar
  Having strange results from an RFID HID card reader - I'm stuck orbisnz 1 1,431 Mar-28-2022, 08:20 AM
Last Post: Larz60+
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 1,447 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  NFC reader code help johnroberts2k 1 2,517 Jul-02-2021, 08:43 PM
Last Post: deanhystad
  csv.reader(): Limit the number of columns read in Windows Pedroski55 9 5,042 Jan-23-2021, 01:03 AM
Last Post: pjfarley3
  Closing Files - CSV Reader/Writer lummers 2 2,561 May-28-2020, 06:36 AM
Last Post: Knight18
  csv reader kgiles 3 5,290 Nov-05-2019, 09:04 AM
Last Post: perfringo
  G code reader luisfelipepc 2 3,645 Aug-13-2018, 02:56 AM
Last Post: ichabod801
  Python code for gcode reader and representation ralmeida 1 6,188 Jul-31-2018, 09:20 AM
Last Post: DeaD_EyE
  AttributeError: module 'csv' has no attribute 'reader' python1234 2 26,776 Jun-08-2018, 06:13 AM
Last Post: python1234

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020