Split with python

John Machin sjmachin at lexicon.net
Tue Aug 29 18:24:49 EDT 2006


Tim Chase wrote:
> Norman Khine wrote:
> > Hello,
> > I have a csv file which is has a field that has something like:
> >
> > text.csv
> > "text (xxx)"
> > "text (text) (yyy)"
> > "text (text) (text) (zzz)"
> >
> > I would like to split the last '(text)' out and put it in a new column,
> > so that I get:
> >
> > new_test.csv
> > "text","(xxx)"
> > "text (text)","(yyy)"
> > "text (text) (text)","(zzz)"
> >
> > how can this be done?
>
> line.rsplit(None, 1)
>
> seems to do the trick for me:
> 

provided the (xxx) etc doesn't contain whitespace.




More information about the Python-list mailing list