I am using Xcode 4.2 and IDLE under Mac OS 10.7 to compile Python 3 code, which is as follows:
#coding=utf-8
print("ľťď")
In spite of using the same interpreter, which is python 3.2.2, while IDLE returns the expected string ľťď (in fact, it works even without the first line—if I understand correctly, this version of Python uses utf-8 as default encoding), Xcode returns an error:
Traceback (most recent call last):
File "/Users/.../main.py", line 2, in <module>
print("\u013e\u0165\u010f")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
How can I achieve the same output in Xcode, please?
I have found the solution thanks to this article.
In case you experience the same issue, all you have to do is create a standard XML property list
~/.MacOSX/environment.plist(case sensitive, extension sensitive) with the key ofPYTHONIOENCODINGand string valueutf-8. Do not forget to log out and log in before testing.For more details, you may found these articles useful:
http://docs.python.org/using/cmdline.html#envvar-PYTHONIOENCODING
http://developer.apple.com/library/mac/#qa/qa1067/_index.html
environment.plist