How can I disable quoting in the Python 2.4 CSV reader? -


I am writing a Python utility for which I need to parse a large, regular updated CSV file That's what I do not control. The utility must run only on a Python 2.4 available server. The CSV file does not cite the field value at all, but I do not think there is any way to close the quote, this is the bid character ( dialect.quotechar = '' ' or whatever). If I try to set the any or the quotation character for the empty string, I get an error.

I set the value around . For some "rare" character, but it is brittle, because there is no ASCII character, I absolutely guarantee that the field value is not in (Except the delimiter, but if i dialect.quotechar = dialect.delimiter , things can be estimated). In

, if I set the bid.quitting to csv.QUOTE_NONE , CSV reader respects this and someone as quote character Does not even explain the letter. Is there a way to duplicate this behavior in Python 2.4?

UPDATE : Thanks to Triptic and Mark Roddy to reduce the problem. Here's a simple-to-display display:

  & gt; & Gt; & Gt; Import CSV & gt; & Gt; & Gt; Import Stringo & gt; & Gt; & Gt; Data = "" "... 1,2,3,4," 5 ... 1,2,3,4,5 ... "" "> gt;> Reader = csv.reader (StringIO stringIo (Data)) >> I read in the reader: Print ... [] Traceback (last call final): File "& lt; Stdin> ", line 1, in? _csv.Error: newline inside string  

The problem occurs when a single double-column in the final Unfortunately, this situation is present in my dataset. I have accepted the solution of the brain: as a non-printing character ( "\ x07" ) BEL ). This is a hack, but it works, and I have not yet done another It has a demo of action in this solution:

  & gt; Import CSV & gt; & gt; Import Stringo & gt; & gt; & gt; ; Class MyDialact (Csv.Dialect): ... quotechar = '\ x07' ... delimiter = ',' ... lineterminator = '\ n' ... doublequat = incorrect ... skipinitialspace = incorrect ... Quoted = csv QUOTE_NONE ... childish = '\\' ... & gt; & gt; bid = MyDialect () & gt; & gt; data = "" "... 1,2 , 3,4, "5 ... 1,2,3,4,5 ..." ""> gt; & Gt; Reader = csv.reader (StringIO stringIo (data), bid = bid) & gt; & Gt; & Gt; I read in the reader ... [] ['1', '2', '3', '4', '5'] ['1', '2', '3', '4' '5']  

Quoting csv.QUOTE_NONE will be sufficient in Python 2.5+ settings, and quotation will then be irrelevant. (I'm actually getting my initial bid through a csv.Sniffer and then overriding the quotation value, no, from subclassing csv.Dialize But I do not want this to be a distraction from the real issue, in the next two sessions, it is displayed that smells is not a problem.)

I do not know what the dragon will want / allow, but you can print without Ssi code like that can use BEL or BS (backspace) These I would be very rare.


Comments