[Csv] multi-character delimiters, take two

Skip Montanaro skip at pobox.com
Fri Feb 7 00:59:39 CET 2003


    Andrew> BTW, have you tried using the csv parser with delimiter set to
    Andrew> space, and skipinitialspace set to true?

    Skip> Not yet.  Good suggestion though.  I will give it a try later.

Here's the result.  Inputs look like this:

    "842"  "6Feb2003"  "16:22:42"  "ce0"  "log"  "drop"  "1433"  "pD955C67D.dip.t-dialin.net"  "stonewall"  "2"  ""  
    "843"  "6Feb2003"  "16:25:21"  "ce0"  "log"  "drop"  "325"  "powered.by.bgames.be"  "129.105.117.83"  ""  " th_flags 14 message_info TCP packet out of state"  
    "844"  "6Feb2003"  "16:28:13"  "ce0"  "log"  "drop"  "nbname"  "200.212.86.130"  "stonewall"  "2"  ""  

The dialect class was defined as:

    class spc(csv.excel):
        delimiter=' '
        skipinitialspace=1

The resulting output looks like:

    ['842', '', '6Feb2003', '', '16:22:42', '', 'ce0', '', 'log', '', 'drop', '', '1433', '', 'pD955C67D.dip.t-dialin.net', '', 'stonewall', '', '2', '', '', '', '']
    ['843', '', '6Feb2003', '', '16:25:21', '', 'ce0', '', 'log', '', 'drop', '', '325', '', 'powered.by.bgames.be', '', '129.105.117.83', '', '', '', ' th_flags 14 message_info TCP packet out of state', '', '']
    ['844', '', '6Feb2003', '', '16:28:13', '', 'ce0', '', 'log', '', 'drop', '', 'nbname', '', '200.212.86.130', '', 'stonewall', '', '2', '', '', '', '']

It didn't actually skip the space, but the data is fairly regular, so I can
live with it.

Thanks again for the suggestion.

Skip


More information about the Csv mailing list