iterating in reverse

Michael Hudson mwh at python.net
Sat Jan 18 17:33:45 CET 2003


Nick Vargish <nav at adams.patriot.net> writes:

> Paul Rubin <phr-n2003b at NOSPAMnightsong.com> writes:
> 
> > If you're just looking for a practical solution, use the locale package,
> > which does this formatting for you.
> 
> I couldn't make this work:
> 
>   >>> locale.format("%d", 1234567, 1)
>   '1234567'
> 
> But thanks for the suggestion.

Well, you need an appropriate locale:

->> locale.setlocale(locale.LC_ALL, 'en_NZ')
'en_NZ'
->> locale.format('%d', 123456, 1)
'123,456'

(found via:

/>> for l in os.listdir("/usr/lib/locale"):
|..  l = locale.setlocale(locale.LC_ALL, l)
|..  conv = locale.localeconv()
|..  if conv['grouping'] and conv['thousands_sep'] == ',':
|..   print l,
\__ 

...)

Cheers,
M.

-- 
  If I had wanted your website to make noise I would have licked
  my finger and rubbed it across the monitor.
                           -- signature of "istartedi" on slashdot.org




More information about the Python-list mailing list