2

I'm new to python and trying to write a python script using the field calculator in ArcMap for a specific field in an attribute table that will calculate and place the values in the other field. My Pre-logic Script Code:


def calcVal(inVal):
    values = {
"BABBBBBBBB":1,
"CCCCCCCCCC":2,
"DDDDDDDDDD":3,
“EEEEEEEEEEE”:4,
etc...}
    if inVal in values.keys():
        return values[inVal]
    else:
        pass

Character “A” in 1st condition ("BABBBBBBBB":1) is non english character. Field calculator does not recognize this text value. Coding is UTF8.

Is a special symbols in python with who I can substitute this non-english character, like % or *?

Or, it is possible to configure this code to recognize UTF8 coding?

1

For how to deal with non-ASCII characters in python, have a look at string encoding. Frankly, this is a pain in the rear in python 2, made much easier in python 3. You can mitigate this somewhat by using unicode literals.

Notice, however, that to save a non-ASCII character to any column in a table, that layer will need to be set to whichever encoding you're using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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