Sorting Objects by property using locale
Donn Ingle
donn.ingle at gmail.com
Fri Dec 21 09:33:21 EST 2007
In follow-up: I think this should work:
# -*- coding: utf8 -*-
import locale
locale.setlocale( locale.LC_ALL, "" )
class Test(object):
def __init__(self,nam):
self.name = nam
def __cmp__(self, other):
return cmp(self.name, other.name)
l = [ Test("ABILENE.ttf"), Test("Årgate.ttf"), Test("årse.ttf"),
Test("Ärt.ttf"), Test("MomentGothic.ttf"), Test("öggi.ttf"),
Test("Öhmygawd.ttf")]
l.sort( cmp=locale.strcoll, key=lambda obj:obj.name )
for i in l: print i.name
Any bugs?
\d
More information about the Python-list
mailing list