Splitting a string

Duncan Booth duncan.booth at invalid.invalid
Tue May 15 15:04:56 EDT 2007


HMS Surprise <john at datavoiceint.com> wrote:

> The string s below has single and double qoutes in it. For testing I
> surrounded it with triple single quotes. I want to split off the
> portion before the first \, but my split that works with shorter
> strings does not seem to work with this one.
> 
> Ideas?
> 
> Thanks,
> jvh
> 
> s = ''''D132258\',\'\',
> \'status=no,location=no,width=630,height=550,left=200,top=100\')"
> target="_blank" class="dvLink" title="Send an Email to selected
> employee">'''
> 
> t = s.split('\\')
> 
> 

Remember that the the backslash used as an escape character is purely part 
of the syntax, it doesn't put a backslash into the string. You used triple 
quotes around the string so you didn't need to quote the other single 
quotes as \' in that case the escaping backslash is simply ignored.

So your string doesn't have any backslash characters in it and splitting on 
a backslash won't do anything useful. If you want to split it before the 
first single quote then use:

t = s.split("'")




More information about the Python-list mailing list