nathaliet

Arcpy - Problem with accents

Discussion created by nathaliet on May 21, 2014
Latest reply on May 24, 2014 by Wayne_Whitley
Hello,

I use arcpy to generate some maps and I have a problem with the accents witch are in the shapefile (I am French so I have a lot of accents in my data !!!)
I don't understand how it works the encoding/coding and the functions decode(), encode() with arcpy.

For example, my script without import arcpy :

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # -*- coding: utf-8 -*-
...
>>> a="é"
>>> print a
é
>>>


with import arcpy :

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # -*- coding: utf-8 -*-
... import arcpy
>>>
>>> a="é"
>>> print a
'
>>>


So I tried with every encode() and decode() with 'Utf-8', 'latin9' ... but I always have errors like UnicodeDecodeError : 'utf-8' codec can't decode byte ...

I have the same error when I print the value in the .dbf of a shapefile.
...
ROWS = arcpy.SearchCursor(LAYER,"","","","")
for row in ROWS:
 print str(row.DESCRIPT)


Thanks !!!

Nat

Attachments

Outcomes