views:

81

answers:

2

Do locales contain information about preferred units for temperature, lengths, etc. on Unix/Linux? Is it possible to access these properties from Python? I checked out the "locales" module, but didn't find anything suitable.

I'd like my application to automatically convert values into the most suitable unit.

+3  A: 

No, that's not possible.

I think every country in the world is on the metric system, with the dubious exceptions of the United States and a few others. With that said, you can be confident about choosing metric.

You'd want to write classes with conversion and math rules to define proper operations for each measure.

You won't know what variables to apply the conversions to, and you won't know if micrometers or kilometers are most appropriate for your length measures. It's necessary to know the measurement system, but not sufficient for problems that want to use units properly.

duffymo
A: 

For what it's worth, KDE offers a choice of "Metric" or "Imperial" as the standard unit system, so I would presume that it's possible to access that information through Python somehow. Gnome might have a similar setting, I'm not sure... but I don't think there's any equivalent for a generic UNIX/Linux system.

The most recent version of SciPy (0.7) includes a module for unit handling, and you can use that to do your conversions if necessary.

David Zaslavsky