Python escape characters?

963
4
09-04-2012 04:50 AM
BartłomiejStaroń
New Contributor III
I receive from tool string

string = 'D:\agsdata\temp.mxd;D:\agsdata\temp1.mxd'
when I use string  receive:

'D:\x07gsdata\temp.mxd;D:\x07gsdata\temp1.mxd'

How to get around?
Tags (2)
0 Kudos
4 Replies
ChristopherThompson
Occasional Contributor III
To preserve that string use an r to escape the backslashes:
string = r'D:\agsdata\temp.mxd;D:\agsdata\temp1.mxd'

Alternatively, backslashes will escape things as well so you can use 2 of them:
string = 'D:\\agsdata\\temp.mxd;D:\\agsdata\\temp1.mxd'
0 Kudos
BruceNielsen
Occasional Contributor III
string = r'D:\agsdata\temp.mxd;D:\agsdata\temp1.mxd'
-or-
string = 'D:\\agsdata\\temp.mxd;D:\\agsdata\\temp1.mxd'
-or-
string = 'D:/agsdata/temp.mxd;D:/agsdata/temp1.mxd'
0 Kudos
BartłomiejStaroń
New Contributor III
I now r,\\ and /.

Problem is that I receives from tool "string" as a value that I later use in script. The tool crash because my script see string with \a, \t.

How to get string from tool provide for \\.
0 Kudos
BruceNielsen
Occasional Contributor III
Is the tool providing the string to your script written by Esri, or was it developed by someone else?
0 Kudos