[wxPython-users] Mystery: wx.grid, a filter function, and Unicode

Bob Klahn bobstones at comcast.net
Thu Jan 3 11:43:25 PST 2008


At 12:50 PM 1/3/2008, Robin wrote:
>Bob Klahn wrote:
>
>>I'm using the above function inside a wx.grid cell renderer:
>>         class CellRenderer(gridlib.PyGridCellRenderer):
>>              def __init__(self):
>>                  gridlib.PyGridCellRenderer.__init__(self)
>>                  self.filter = utils.makefilter('{}\x08\x0C',delete=True)
>>
>>The problem:  When the cell renderer executes 
>>and the filter is invoked (e.g., as self.filter(word) ), it fails on the
>>         return s.translate(allchars, delchars)
>>line in makefilter:
>>     TypeError: translate() takes exactly one argument (2 given)
>>I.e, Python thinks that string s is a Unicode 
>>string.  But I'm not using Unicode strings 
>>anywhere!  Any ideas where wxPython might be 
>>changing my plain strings into Unicode 
>>strings?  I'm not able to provide a simple code example.
>>Filters generated by makefilter work perfectly 
>>outside of my wxPython application.
>
>Where does word come from?  Have you checked 
>it's type? http://wiki.wxpython.org/UnicodeBuild

The overall problem:  The external data I need to 
read in and write out is the "extended ASCII" seen here:
http://www.cdrummond.qc.ca/cegep/informat/Professeurs/Alain/files/ascii.htm

Included in this external data are a number of 
accented characters, vertical lines 
(extended-ASCII B3), and broken bars (extended-ASCII 7C).

How should I be dealing with this data?  E.g., 
none of the codecs I've tried can handle the 
vertical-line data.  When I try to do so, e.g., 
using utf-8, the error message 
"UnicodeDecodeError: 'utf8' codec can't decode 
byte 0xb3 in position 18: unexpected code byte" is returned.

How should I handle phrases such as "Déjà 
vu"?  Externally, the é and à are recorded as hex 
82 and hex 85 respectively; internally, they 
should presumably be hex E9 and hex E0 
respectively.  How do I get "Déjà vu" back from 
Unicode to extended ASCII?  All of the encode 
methods I've applied to Unicode string "Déjà vu" 
(e.g., latin1, ISO-8859-1, utf-8, utf-16) fail.

Clearly I'm Unicode-challenged.  Spoon-feeding 
needed!  To whomever:  If you give this a shot, 
please make sure your code can handle both the 
accented characters and the vertical lines and broken bars.

Bob




More information about the wxpython-users mailing list