I have a Python application that receives multilingual information from websites and presents them in a small GUI window (based on wxpython).I (currently) do not use any specific Unicode instructions in my source files.
Now, when I launch a python application from Eclipse, French characters (e.g. Γ«) display well, when I launch it from a packaged version of py2exe, the character becomes awkward. I really don't understand why, since building with py2exe does not cause Unicode or encoding errors.
However, to fix this problem and after this article, I wrapped the lines in a call unicode(my_string, "utf-8")before displaying it on the screen. This solves it.
unicode(my_string, "utf-8")
Questions:
unicode()
I've tried wrapping my head around Unicode many times already, but it looks like I'm not Unicode compatible: - |
The best approach is to ensure that the strings are unicode as soon as possible . If the library that you clean on sites does not prove that you are using unicode, then they do not do what they should (imho). Then you must decode them to Unicode yourself, using the same encoding that the web pages that you clear use.
, . , , - , -utf8. iso-8859-1 .
Eclipse, Windows.exe?.
, PyDev Eclipse?
, PyDev sys.getDefaultEncoding() "utf-8". , ( - ) UTF-8. , (, ascii Windows)
ascii
- u :
u
u"the string"
, UTF-8. Python 3 +
, , , Eclipse, UTF-8 py2exe Windows, -1.
py2exe
unicode(a_string, "UTF-8"), unicode Python UTF-8. , .
unicode(a_string, "UTF-8")
unicode //, print. , , - string as.
print
string
, @top , - # -*- coding: utf-8 -*-, " IS UTF-8"?
# -*- coding: utf-8 -*-
unicode.