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

I downloaded a csv database with names and dates etc..
I can read it partially, line per line, split on ',' and get the values i want;
Except that some of the lines, especially the first name of the person, have strange chars.
I cannot even read past the first occurrence like this.
How can i read past these chars and not loose the rest of the line ?
1924,"DUPONT, Clément",FRA,Men,Rugby,Silver
f = open(file,'r')
for line in f:
    try:
        l = line[:-1]
        l = l.split(',')
    except:
        pass
f.close()
Output:
Traceback (most recent call last): File "E:/Python/Olympics2.py", line 13, in <module> for line in f: File "K:\Python383\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 0x81 in position 6872: character maps to <undefined>
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Messages In This Thread
csv troubles - by DPaul - Aug-13-2020, 10:15 AM
RE: csv troubles - by Gribouillis - Aug-13-2020, 12:07 PM
RE: csv troubles - by DPaul - Aug-13-2020, 02:54 PM
RE: csv troubles - by Gribouillis - Aug-13-2020, 03:34 PM
RE: csv troubles - by DPaul - Aug-13-2020, 05:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  troubles with tqdm max22 2 526 Nov-27-2023, 09:20 PM
Last Post: max22
  Installation troubles on Win 10 peringek 1 2,944 Dec-31-2020, 07:30 AM
Last Post: caleb_cruze
  converting user input to float troubles RecklessTechGuy 3 2,489 Aug-17-2020, 12:41 PM
Last Post: deanhystad
  Win32API Troubles daaaabs 2 2,961 Mar-24-2020, 08:19 PM
Last Post: daaaabs
  local variable troubles yokaso 4 3,210 Oct-20-2019, 05:25 PM
Last Post: ichabod801
  Troubles with instaling pocketsphinx Thais781 1 2,640 Aug-07-2018, 10:05 AM
Last Post: Larz60+
  Troubles with classes, taken from a book sylas 2 3,208 Jun-05-2017, 08:39 AM
Last Post: sylas
  [?] UTF8, Unicode and Binary data reading troubles doublezero 1 3,171 Mar-31-2017, 11:32 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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