2

I need to assign a value depending on other two columns "FNP" and "Teilort". I wrote this script in phyton for field calculator. It actually works (no error messages) but the results in every cell is 99.

I checked the two columns "FNP" and "Teilort" and the problem doesn't look like to com e from there (no extra blank or white spaces).

What can be the problem?

enter image description here

1 Answer 1

4

Apparently RefName never equals your comparison strings. All constant strings includes German characters ä or ü, but you don't use the "u" constant string prefix. Depending on the incoming string's format the comparison might not be what you expekt.

You should write if RefName==u"Flächen für die Landwirdshaft" and make sure that RefName also is a correct formatted unicode string.

EDIT: Do some print of RefName-column of your dataset in a python window in ArcMap to see how the strings look like.

Add the dataset to the map and select a row with RefName="Flächen für die Landwirdshaft"

type the following rows in the pyton window (replace names with your actual names):

curs=arcpy.SearchCursor("<name of layer>")
feat=curs.next()
feat.getValue("<name of column for RefName>")

The last row will probably print out something like u'Fl\xe4chen ...', which means you have a valid unicode string to compare against. Also try print feat.getValue("") to see that it prints like the literal you are comparing with. Note that the == operator is case sensitive.

3
  • Thankyou for your reply. Just a question: RefName==u"Flächen für die Landwirdshaft" what does change with the "u" before the string? In this way are recognized also ü, ä, ö? Oct 20, 2014 at 9:24
  • Nope, it doesn't improve with the "u": the result is always 99. What do you mean with "correct formatted unicode string", the two coloumns are type "text" and 50 charachters, are there more options? Oct 20, 2014 at 10:01
  • 1
    The u denotes that the string literal should be interpreted as an unicode string, which is necessary as it contains german letters. Read more on docs.python.org/2/howto/unicode.html
    – Stefan
    Oct 20, 2014 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.