# bittorrent-console.py
def fmtsize(n): s = str(n)
size = s[-3:]
while len(s) > 3:
s = s[:-3]
size = '%s,%s' % (s[-3:], size)
if n > 999:
unit = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
i = 1
while i + 1 < len(unit) and (n >> 10) >= 999:
i += 1
n >>= 10
n /= (1 << 10)
size = '%s (%.0f %s)' % (size, n, unit[i])
return size
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25966/viewspace-132884/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/25966/viewspace-132884/