Re: Problem in splitting a string

From: wes weston (wweston_at_att.net)
Date: 07/22/04


Date: Thu, 22 Jul 2004 18:36:13 GMT

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.
>
> How can I do that?
>
> Thanks in advance
>
> Angelo
>
>
>
> --
> ========================================================
> Angelo Secchi PGP Key ID:EA280337
> ========================================================
> Current Position:
> Graduate Fellow Scuola Superiore S.Anna
> Piazza Martiri della Liberta' 33, Pisa, 56127 Italy
> ph.: +39 050 883365
> email: secchi@sssup.it www.sssup.it/~secchi/
> ========================================================
Angelo,

>>> list = ',,,,,,23,,,asd,,,,,"name,surname",,,,,,,\n'.split(',')
>>> print list
['', '', '', '', '', '', '23', '', '', 'asd', '', '', '', '', '"name', 'surname"', '', '', '', '', '', '', '\n']
>>>

Could you split the strings; then recombine list[14] + ',' + list[15] ?
wes



Relevant Pages

  • Re: Problem in splitting a string
    ... Angelo Secchi wrote: ... > that particular comma. ... You may want to look at regular expressions, but in the example you gave, ... you just have to split the string at the quotation marks, ...
    (comp.lang.python)
  • Re: Problem in splitting a string
    ... Byron ... Angelo Secchi wrote: ... In other word I would like python in separating fields to skip ... > that particular comma. ...
    (comp.lang.python)
  • Re: Problem in splitting a string
    ... "Angelo Secchi" wrote in message ... In other word I would like python in separating fields to skip ... > that particular comma. ... Download pyparsing at http://pyparsing.sourceforge.net. ...
    (comp.lang.python)
  • Re: Problem in splitting a string
    ... Angelo Secchi wrote: ... >I have string of numbers and words like ... >that particular comma. ... working on a DSV module that would handle all of this stuff, ...
    (comp.lang.python)
  • Problem in splitting a string
    ... I have string of numbers and words like ... In other word I would like python in separating fields to skip ... that particular comma. ... Current Position: Graduate Fellow Scuola Superiore S.Anna Piazza Martiri della Liberta' 33, Pisa, 56127 Italy ph.: +39 050 883365 ...
    (comp.lang.python)