For American numbers

Peter Hansen peter at engcorp.com
Sun Feb 13 08:57:58 EST 2005


Pierre Hanser wrote:
> Peter Hansen wrote:
> 
>> Scott David Daniels wrote:
>>
>>> Kind of fun exercise (no good for British English).
>>>
>>>     def units(value, units='bytes'):
>>>         magnitude = abs(value)
>>>         if magnitude >= 1000:
>>>             for prefix in ['kilo mega giga tera peta '
>>>                            'exa zetta yotta').split():
>>>                 magnitude /= 1000.
>>>                 if magnitude < 1000.:
>>>                     break
>>
>>
>>
>> Only for hard drive manufacturers, perhaps.
>>
>> For the rest of the computer world, unless I've missed
>> a changing of the guard or something, "kilo" is 1024
>> and "mega" is 1024*1024 and so forth...
> 
> even for cpu frequency?

I don't think so.  But who cares?  CPU frequency, apart
from being fairly meaningless anyway, doesn't cover
enough ground for anyone to need a routine like the
above to deal with it.

Anyway, I was focusing on the "units='bytes'" part above
which suggested a byte-oriented focus for the routine,
and CPU frequencies aren't measured in bytes...

-Peter



More information about the Python-list mailing list