Problem in splitting a string

Jeff Shannon jeff at ccvcorp.com
Thu Jul 22 15:11:04 EDT 2004


Angelo Secchi wrote:

>Hi,
>I have string of numbers and words like
>
>',,,,,,23,,,asd,,,,,"name,surname",,,,,,,\n'
>
>and I would like to split (I'm using string.split()) it using comma as
>separator but I do not want to split in two also the "name,surname"
>field. In other word I would like python in separating fields to skip
>that particular comma.
>  
>

You may be able to use regular expressions (the re module) to hack 
something together that'll work for your particular case.  In the 
general case, though, splitting delimiter-separated values in the 
presence of quoting and escaping is a nontrivial problem. 

I remember some discussion, quite a while ago, about several people 
working on a DSV module that would handle all of this stuff, but I don't 
know what became of that.

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list