Does anyone know of a way to represent Non-ASCII symbols such as this symbol "ŷ" on python in a print statement?
Asked
Active
Viewed 215 times
0
-
2Use Unicode.... https://docs.python.org/2/howto/unicode.html – Robert Harvey Jun 09 '14 at 02:39
1 Answers
-1
You should use the UTF-8 coding system.
The first line of your Python file should be:
# -*- coding: utf-8 -*-
If this doesn't work, try wrapping your string with unicode(string).
print unicode("éáóý");
If this still doesn't work, try adding these lines before all code but after # -- coding: utf-8 --
import sys
if not hasattr(sys, "setdefaultencoding"):
reload(sys)
sys.setdefaultencoding("utf-8")
Finally, make sure that you are saving the file as UTF-8 and that your console supports unicode characters.

Zenadix
- 15,291
- 4
- 26
- 41
-
-
@user3720526: If you're trying to display one character and getting another, then you need to say that in your question. – Robert Harvey Jun 09 '14 at 02:51
-
I am sorry, I will try to be more specific in future questions from now on. – user3720526 Jun 09 '14 at 02:54
-
-
Yup, it worked. I'm going to have to study unicode on python more now. – user3720526 Jun 09 '14 at 03:18