Paul McNett <[EMAIL PROTECTED]> writes: > Chris Mellon has given you the best response: use the locale module > for this.
It may be the best choice as far as reuse is concerned, but it's not without serious drawbacks. For one, the locale model doesn't really allow forcing of the separators. Some locales, such as the "C" locale, define no thousand separators whatsoever. Since many Unix installations are set up to use the "C" locale because it is the OS default, this problem must be addressed. Chris addresse it by forcing the locale to "US", but that is a step away from the locale model because it consciously overrides the user's locale preferences. By doing that, one forces a particular way of grouping thousands, without the possibility to using a different grouping characters or to group by a different number of digits (some locales group by tens of thousands). That is quite similar to what you get when you implement the desired grouping yourself. Setting the locale makes the code platform-dependent because different platforms have different locale names. For example, Chris's code fails for me with "unsupported locale name" -- apparently, my system calls the US locale is "en_US.utf8". (Even specifying "en_US" doesn't work. It might be a Python or system problem, but it just doesn't work.). Finally, it makes the code OS-installation-dependent -- even under the same OS, different installs can and do set up different locales. If his number presentation calls for thousand separators, coding them manually is not an unreasonable implementation choice. > It seems like you are looking for a spoonfed solution rather than > looking for guidance on how to solve the problem for yourself. If > I'm wrong about that assessment, I apologize in advance. No argument here. -- http://mail.python.org/mailman/listinfo/python-list