How to handle spaces and special characters in arcpy.Select_analysis?

1514
3
Jump to solution
07-25-2014 11:07 AM
ChrisBrannin
Occasional Contributor

Hello

How do I handle ' in an attribute table using python?

Example

var = ["'Name"]

any help is greatly appreciated!

Cheers

Chris

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
IanMurray
Frequent Contributor

I'd just use a backslash as an escape character, that way it doesn't try doesn't crash since there isn't a second single quote to end the string.

var = ["\'Name"]

Generally it not advisable to have special characters in field names, or to have them start with numbers.

View solution in original post

0 Kudos
3 Replies
IanMurray
Frequent Contributor

I'd just use a backslash as an escape character, that way it doesn't try doesn't crash since there isn't a second single quote to end the string.

var = ["\'Name"]

Generally it not advisable to have special characters in field names, or to have them start with numbers.

0 Kudos
ChrisBrannin
Occasional Contributor

Thanks for the idea!

Working code below:

var = ["'\'Name"]

0 Kudos
KimOllivier
Occasional Contributor III

I avoid escape characters by using triple quotes. It is so much easier and more legible.
Except when it is the first character when it is a bit hard to see.

0 Kudos