1

I get this error using Python while I'm trying to label a shapefile. The strange thing is that for other shapefiles the code works.

There is a table (relates.dbf) that has the data to be used for labelling and it has the fields: Schacht (string), Auswahl (short integer), max_Übers (double) and Max_Wieder (double).

The problem shouldn't be there.

NB: The SQL for this labelling class is [TN_UEB] > 0 and I use ArcGIS 10.3.1. The code is a variation of http://support.esri.com/technical-article/000012230

Any clues? What does it mean "line 0"! Where's the problem?

def FindLabel ([Name], [TN_UEB]):
  import arcpy

  key1 = [Name]
  key2 = "Schacht"
  key3 = "Auswahl"
  L =  "<FNT size = '10'><BOL>" + [Name] + "\n" +  " Ta = " + [TN_UEB] + " a" + "</BOL></FNT>" + "\n"
  L2 = "max_Übers"
  L3 = "Max_Wieder"
  myDataTable = r"P:\Duesseldorf\50009\FOG\Bestand_pz\Vergleich_Ergebnisse\KOSTRA_Auswertung\Variante_1_D_neuneu\relates.dbf"

  cur = arcpy.da.SearchCursor(myDataTable, [key2, L2, L3, key3])
  for row in cur:
    if str(key1) == str(row[0]) and row[3]>0:
      L = L + str(round(float(row[1]),1)) + " m" + "<SUP>"+"3"+"</SUP>" + " (T=" + str(round(float(row[2]),1)) + "a)" + "\n"
  return L

Error

5
  • str is only synonymous with Unicode at Python 3.x. If your field contains UTF-8 data you must process it differently.
    – Vince
    Commented Dec 20, 2016 at 13:19
  • What do you exactly mean? How should I process them differently? Commented Dec 20, 2016 at 13:33
  • I tried just for one element where I know that all the strings are actually just numbers. Same error. Any other ideas? Commented Dec 20, 2016 at 13:59
  • maybe your ü is posng a problem?
    – radouxju
    Commented Dec 20, 2016 at 19:48
  • I changed ü with ue in the table, but still it doesn't work Commented Dec 22, 2016 at 12:04

1 Answer 1

1

You can try adding the coding at the beginning of your script:

# coding: utf-8

In your script you can try to declare all strings with a u in front:

u'strings' 

This refferrs to Python 2, as for Python 3 Unicode is default, but maybe it's worth to give it a shot. (You didn't mention which Python version you are using.)

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.