# Bugfix, non ritornava per quelli sopra i 1024 PiB
def f(
bytes,
factor=1024,
labels=['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi'],
precision=4 ):
for x,y in map(
lambda x: ( factor**(x[0]+1),
('%.' + str(precision) + 'lf %sB') % (bytes / factor**x[0], x[1])
),
enumerate(labels)
):
if (bytes < x):
return y
# รจ un po' bruttino
return ('%.' + str(precision) + 'lf %sB') % (bytes / factor**len(labels),
labels[-1])
# Test
for x in range(16):
y = 512.12*(10**x)
print f(y)
--
Wyrmskull
_______________________________________________
Python mailing list
[email protected]
http://lists.python.it/mailman/listinfo/python