From: Peter L. <pet...@te...> - 2009-07-02 08:46:50
|
Den Thursday 02 July 2009 10.38.17 skrev Benny Malengier: > 2009/7/2, Peter Landgren <pet...@te...>: > >> Peter, can you check for certainty that strxfrm really does not work > >> if unicode is passed, so change the above in > >> d = sorted((locale.strxfrm(x.decode("utf-8")),x) for x in b) > > > > Gives this in winxp: > > == List b sorted with strxfrm on OS encoding === > > Traceback (most recent call last): > > File "sorttestben.py", line 71, in <module> > > d = sorted((locale.strxfrm(x.decode("utf-8")),x) for x in b) > > File "sorttestben.py", line 71, in <genexpr> > > d = sorted((locale.strxfrm(x.decode("utf-8")),x) for x in b) > > UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in > > position 0: > > ordinal not in range(128) > > > > and in Linux: > > == List b sorted with strxfrm on OS encoding === > > Traceback (most recent call last): > > File "SortTestBen.py", line 71, in <module> > > d = sorted((locale.strxfrm(x.decode("utf-8")),x) for x in b) > > File "SortTestBen.py", line 71, in <genexpr> > > d = sorted((locale.strxfrm(x.decode("utf-8")),x) for x in b) > > UnicodeEncodeError: 'ascii' codec can't encode character u'\xc5' in > > position 0: ordinal > > not in range(128) > > Ok, this means strxfrm internally encodes with ascii which is failing. > Sorry to say this, but can you try again with what GRAMPS does in linux: > > d = sorted((locale.strxfrm(unicode(x, "utf-8")), x) for x in b) > > I was expecting this to be the same as the decode, but as linux > crashes with ascii and GRAMPS works just fine to sort lists, I suppose > there is a difference. > > Benny Result: == List b sorted with strxfrm on OS encoding === Traceback (most recent call last): File "sorttestben.py", line 72, in <module> d = sorted((locale.strxfrm(unicode(x, "utf-8")), x) for x in b) File "sorttestben.py", line 72, in <genexpr> d = sorted((locale.strxfrm(unicode(x, "utf-8")), x) for x in b) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 0: ordinal not in range(128) /Peter |