the goal of my program is to retrieve data from a field one after another at the end to compare with other values of another table when I execute the code that allows me to point to the values of the first field I get a string that starts with u ' What should I do to remove the u'

DataSource= Shapefile

for row in cursor:

i get this

>>>>(u'ROAD 1',)
    (u'ROAD 2',)
  • I think you will find that the u makes no difference to what you are trying to do. If you find it does then can you elaborate about any problem beyond aesthetics that it causes. – PolyGeo Apr 22 '16 at 14:30
  • Please edit th question to specify the data aource type (e.g., file geodatabase, shapefile,...), and the field type. You haven't demonstrated a problem with encoding, just a fact of encoding. – Vince Apr 22 '16 at 14:43
  • the problem is when I compare the value " ROAD 1" another value with the == operator even if there is a conection the program does not recognize it – BORUSSEN11 Apr 22 '16 at 14:49
  • 3
    Casting between unicode and str is a Python issue (more specifically, Python 2.7, since Python 3.x uses unicode as str). Have you tried casting with str() or prefixing your comparison constant with u? – Vince Apr 22 '16 at 15:16

The u'' just indicates that the string is encoded as unicode rather than ASCII. If you print just the string with print(row[0]) (instead of the whole row tuple) you should see the values as you'd expect, e.g. ROAD 1.

| improve this answer | |
  • even with the row [0] I still have the "u" which appears – BORUSSEN11 Apr 22 '16 at 14:45

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.