How do I parse this ? regexp ?

Robert Kern rkern at ucsd.edu
Wed Apr 27 13:30:26 EDT 2005


serpent17 at gmail.com wrote:
> Thank you, it works, but I guess not all the way:
> 
> for instance, I have this:
> 04242005 18:20:42-0.024329, 271.2469504, [-4.097900390625,
> 3.4332275390625, 105.062255859375], [0.0384521484375, 0.08416748046875,
> -1.026885986328125], [0.00640869140625, 0.00885009765625,
> 0.00701904296875]
> 
> translates into
> 
> 
> '04242005 18:20:42-0.024329  271.2469504   -4.097900390625
> 3.4332275390625  105.062255859375    0.0384521484375  0.08416748046875
> -1.026885986328125    0.00640869140625  0.00885009765625
> 0.00701904296875 \n'
> 
> but I need to remove the first - between 18:20:42 and 0.024329 but not
> the others.

Use the find() method on the string to locate the index of this first 
'-', then break the line into two parts before and after the '-'.

You should spend some quality time with the string documentation to 
internalize the possibilities for yourself. There's only so much work we 
can do for you. Also, take a look at David Mertz's fine _Text Processing 
in Python_ available in dead-tree form or online.

http://gnosis.cx/TPiP/

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list