[Tutor] Using split with a backslash

Bryan Fodness bryan.fodness at gmail.com
Wed Apr 2 18:14:34 CEST 2008


Thanks everyone,
I was trying it this way.

x1, x2 = LeafJawPositions.split(r'\\')




On Wed, Apr 2, 2008 at 11:00 AM, Michael Connors <connorsml at gmail.com>
wrote:

>
>  >>> LeafJawPositions='-42.000000000001\29.800000000001'
> > >>> LeafJawPositions
> > '-42.000000000001\x029.800000000001'
> > >>> x1, x2 = LeafJawPositions.split('\x0')
> > ValueError: invalid \x escape
> > >>> x1, x2 = LeafJawPositions.split('\')
> >
> > SyntaxError: EOL while scanning single-quoted string
> > >>>
> >
> > Hi,
> The backslash is used for escaping special characters in a string. In
> order to do what you are trying to do, you would need to escape the
> backslash using a backslash.
> You need to do this in two places in the above code.
> LeafJawPositions='-42.000000000001\\29.800000000001'
>
> and
>
> x1, x2 = LeafJawPositions.split('\\')
>
> http://docs.python.org/ref/strings.html
>
> Regards,
> Michael
>
>


-- 
"The game of science can accurately be described as a never-ending insult to
human intelligence." - João Magueijo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/e0b32e4a/attachment.htm 


More information about the Tutor mailing list