On Wed, Apr 02, 2008 at 10:44:10AM -0400, Bryan Fodness wrote:
> I have a data pair separated by a backslash. I didn' t think it would see
> an end of line if the backslash was inside the quotes.
> Can this be done? I don't have a choice in what the separator is.
>
> >>> 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
> >>>
In a literal string, backslash is an escape character. In order to
include a backslash in a literal string, type two backslashes.
Example:
x1, x2 = LeafJawPositions.split('\\')
See http://docs.python.org/ref/strings.html
Another example:
In [1]: a = 'abc\\def\\ghi'
In [2]: len(a)
Out[2]: 11
In [3]: a.split('\')
------------------------------------------------------------
File "<ipython console>", line 1
a.split('\')
^
SyntaxError: EOL while scanning single-quoted string
In [4]: a.split('\\')
Out[4]: ['abc', 'def', 'ghi']
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor