Python, the best approach to support Unicode?

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.

Questions:

  • Is the carry string in a call unicode()before displaying a good way to do this?
  • Why does it work without Unicode conversion from Eclipse, but not from a version of Windows.exe?

I've tried wrapping my head around Unicode many times already, but it looks like I'm not Unicode compatible: - |

+3
source share
3 answers

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 .

+6

Eclipse, Windows.exe?.

, PyDev Eclipse?

, PyDev sys.getDefaultEncoding() "utf-8". , ( - ) UTF-8. , (, ascii Windows)

- u :

u"the string"

, UTF-8. Python 3 +

+1

, , , Eclipse, UTF-8 py2exe Windows, -1.

unicode(a_string, "UTF-8"), unicode Python UTF-8. , .

unicode //, print. , , - string as.

, @top , - # -*- coding: utf-8 -*-, " IS UTF-8"?

unicode.

0
source

All Articles