string.split escaping

Dave Harrison dave at nullcube.com
Thu May 29 02:17:42 EDT 2003


Ok I should probably change the post a little ...

My intention (as the subject suggested) was to find a way of escaping the
split value.

This means I want to be able to ignore my split character at any part of the string ... not just at the end, so maxsplit isnt what Im after.

Andrew Bennetts (andrew-pythonlist at puzzling.org):
> On Thu, May 29, 2003 at 04:03:37PM +1000, Dave Harrison wrote:
> > If I have a string 
> > 
> > a = 'dog;cat;big;dog'
> > 
> > How do I escape the last ';' so that when I call 
> > 
> > string.split(a, ';')
> > 
> > I get
> > 
> > ['dog', 'cat', 'big;dog']
> 
> If you know how many splits you want, use the optional "maxsplit" argument:
> 
> >>> 'dog;cat;big;dog'.split(';', 2)
> ['dog', 'cat', 'big;dog']
> 
> -Andrew.
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list