0

I tried all in this interesting thread Changing default encoding of Python? but nothing work for me. I use sublime text and when I try :

import sys
print(sys.stdout.encoding)

Output is : US-ASCII

I have a python script that works perfectly under Windows (Output is : utf-8)

But on osx 10.10.2, I always have a problem

Another thing that might help for answer, when I try in python shell (osX) this code :

>>> leString = '/Users/djex/Desktop/dosser\ é\ espace'
>>> type(leString)
<class 'str'>

>>> stringNew = leString.encode('utf-8')
>>> type(stringNew)
<class 'bytes'>

>>> print (stringNew)
b'/Users/djex/Desktop/dosser\\ \xc3\xa9\\ espace'

>>> print (stringNew.decode('utf-8'))
/Users/djex/Desktop/dosser\ é\ espace
>>>

All is ok.but...

when I try the same thing in sublime text (osX), it does not work

i always have this error

unicodeencodeerror 'ascii' codec can't encode character '\u0300' blabla

or error like

'str object has no attrbute decode'

I do not really understand where my problem comes

Ty for your help

Community
  • 1
  • 1
jmercier
  • 564
  • 2
  • 7
  • 17

1 Answers1

0

Found, my problem was in python.sublime-build file

this file does not have "env" line

{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf-8",
"env": {"LANG": "fr_FR.UTF-8"}
}
jmercier
  • 564
  • 2
  • 7
  • 17