Cool steven, very helpful
I have a db which holds units data it will avoids me to do such format
conversion.
Thnx
Cheers
Karim
Le 15/05/2012 10:30, Steven D'Aprano a écrit :
I am pleased to announce a new release of byteformat.
http://pypi.python.org/pypi/byteformat
byteformat is a Python module for intelligently formatting numbers of
bytes using common human-readable strings:
from byteformat import format
format(12000)
'12 KB'
format(5100000, style='ABBREV')
'5.1 Mbytes'
format(48500000000000, style='LONG')
'48.5 terabytes'
byteformat understands SI decimal units, IEC binary units, and mixed
units:
format(12000, scheme='IEC')
'11.7 KiB'
format(12000, scheme='MIXED')
'11.7 KB'
You can also specify which prefix to use:
format(48500000000000, style='LONG', prefix='M')
'48500000 megabytes'
byteformat can be used as a command-line tool:
[steve@ando ~]$ python -m byteformat --prefix=K 1000 12300 145000
1 KB
12.3 KB
145 KB
byteformat understands all the relevant SI and IEC unit prefixes, and is
released under the MIT licence.
--
http://mail.python.org/mailman/listinfo/python-list