Unicode confusion

Footnote: I discovered that I can use (for example)
  sre.compile(r"[ae\x8fiouy]+")
to match the accented e -- but only after I *also* do
  defEnd = wx.GetDefaultPyEncoding
  wordstring = wordstring.encode(defEnd)
and send that encoded wordstring to the regex matching code, where it *will* catch the >128 character. This seems *awfully* roundabout. Will it work cross-platform? It means I have to import wx into that module though it's used for nothing else. Am I missing some simpler approach? This must come up all the time, in Python I mean, not just with wxPython. . . .

Charles Hartman

Charles Hartman wrote:

Footnote: I discovered that I can use (for example)
    sre.compile(r"[ae\x8fiouy]+")
to match the accented e -- but only after I *also* do
    defEnd = wx.GetDefaultPyEncoding
    wordstring = wordstring.encode(defEnd)
and send that encoded wordstring to the regex matching code, where it *will* catch the >128 character. This seems *awfully* roundabout. Will it work cross-platform?

I think so.

It means I have to import wx into that module though it's used for nothing else.

wx.GetDefaultPyEncoding() will return a string, so you can just add an encoding parameter to the functions you call in that module and pass the value from wx.GetDefaultPyEncoding() (or any other encoding name).

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!