Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: fixing an horrific formatted csv file. Date: Fri, 04 Jul 2014 18:19:09 +1200 Lines: 17 Message-ID: References: <47e2e29d-b5c3-4aa6-abf9-3b1e46eb0dec@googlegroups.com> <0d3871c6-81d4-4168-9408-ad85299b0955@googlegroups.com> <11ecf009-6f81-4fa5-bee9-b52b9407f0af@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net pvtwVQ/DKPXBCDrF43EtagDklgRZ5dHBPs0iCmesekWN55Z2Lh Cancel-Lock: sha1:IFJoZpy8Re9r3693MFYAqT6seWQ= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <11ecf009-6f81-4fa5-bee9-b52b9407f0af@googlegroups.com> Xref: csiph.com comp.lang.python:73937 flebber wrote: > so in my file I had on line 44 this trainer name. > > "Michael, Wayne & John Hawkes" > > and in line 95 this horse name. Inz'n'out > > this throws of my capturing correct item 9. How do I protect against this? Use python's csv module to read the file. Don't try to do it yourself; the rules for handling embedded commas and quotes in csv are quite complicated. As long as the file is a well-formed csv file, the csv module should parse fields like that correctly. -- Greg