3

Accentuated are not well displayed in my Toolbox made with ArcPy.

For instance :

def __init__(self):
    """Define the tool (tool name is the name of the class)."""
    self.label = "Sample éééé"

Produce the following output while executing from ArcMap :

Sample éééé

é become é

1 Answer 1

3

ArcMap uses the following encoding cp1252

In order to make accentuated characters well displayed in ArcMap UI.

First add the following import and set encoding to utf-8 at the beginning of your .pyt file.

import sys 
reload(sys)
sys.setdefaultencoding("utf-8")

reload is needed because : https://stackoverflow.com/questions/21393758/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe5-in-position-0-ordinal

Then every string you display in the UI must be formated like this :

sampleString = "éééé"    
sampleString.encode('cp1252') #output : éééé
3
  • 1
    +1 I have just tested and found this to work. I used sampleString = "éééé".encode('cp1252') rather than on two lines.
    – Midavalo
    Feb 22, 2017 at 21:27
  • I am confused though @Marc_Alx, your link doesn't explain why reload() is needed that I can see?
    – Midavalo
    Feb 22, 2017 at 21:30
  • Maybe this question could help on understanding the use of reload though it seems that it's more a 'hack' than a solution due to potential side-effects.
    – Marc_Alx
    Feb 23, 2017 at 9:12

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.