I made a small tool that can be run from a toolbox. It has a validation code to choose multiple values from a specified field from a specified feature layer. It looks quite ordinary:
The validation code is:
def updateParameters(self):
if self.params[1].altered:
if self.params[1].value:
values = set()
inlayer = self.params[0].value.value
fieldname = self.params[1].value.value
cursor = arcpy.SearchCursor(inlayer, None, None, infield)
for row in cursor:
values.add(row.getValue(infield))
self.params[2].filter.list = sorted(values)
It gives me a nice multivalue list of values. But when I check some of them and run a simple script:
import arcpy
# Variables
inlayer = arcpy.GetParameterAsText(0)
infield = arcpy.GetParameterAsText(1)
invalues = arcpy.GetParameterAsText(2)
arcpy.SetParameter(3, invalues)
selected_values = invalues.split(";")
for selected_value in selected_values:
arcpy.AddWarning(selected_value)
then it returns some unicode strings with an apostrophe and some not. I found out that if there is a gap in the value, it returns an unicode string with an apostrophe. I don´t get it why? There´s a example output of the forementioned script:
In this tool window I can see that these apostrophes already figure as input values!
Why is that, and how do I avoid it?
These inputs with apostrophes troubles me further in my script because
if "withoutgap":
# returns True but
if "with gap":
# returns False because the unicode string has apostrophes
running on Windows 8.1, ArcGIS for Desktop 10.1 Basic, Python 2.7