[Tutor] Using split with a backslash

Sander Sweers sander.sweers at gmail.com
Wed Apr 2 17:57:17 CEST 2008


On Wed, Apr 2, 2008 at 7:44 AM, Bryan Fodness <bryan.fodness at gmail.com> 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.

The backlash is seen as an escape character.

Try the below, notice the string prefix r and that the backslash is
now escaped by another backslash.

>>> LeafJawPositions=r'-42.000000000001\29.800000000001'
>>> LeafJawPositions
'-42.000000000001\\29.800000000001'
>>> x1, x2 = LeafJawPositions.split('\\')
>>> x1, x2
('-42.000000000001', '29.800000000001')

See http://docs.python.org/ref/strings.html for more info.

Greets
Sander


More information about the Tutor mailing list