Trouble sorting lists (unicode/locale related?)

Martin v. Löwis martin at v.loewis.de
Mon Sep 22 01:47:19 EDT 2003


jjl at pobox.com (John J. Lee) writes:

> > >>If this did work, then you can use the DSU pattern like so:
> > > [...strxfrm...]
> > > The advantage of which is that you don't have to mess with the
> > > locale.
> > 
> > No, it doesn't.
> 
> It does set the locale, you mean?  

Calling locale.strxfrm does not cause locale.setlocale to be called,
i.e. it does not set the locale.  Likewise, calling locale.strcoll
does not cause setlocale to be called.

Instead, the application needs to call setlocale *explicitly* for
proper operation of either function.

> So I guess there's no advantage there at all?

Using strxfrm is an advantage if you have to collate the same string
multiple times, e.g. when sorting a list of strings. It is an
advantage because sorting will complete faster.

Regards,
Martin




More information about the Python-list mailing list