On 12/01/2011 12.25, lordkrandel wrote: > def f( bytes, factor, labels, precision ): > for i, label in enumerate(labels,1): > n = factor ** i > if (bytes< n) or (label == labels[-1]): > return ('%.*lf %s') % (precision, bytes * factor / n, label) > def f_test(): for x in range(22): y = 512*(10**x) print f(y, 1024, ('bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'), 4) print ' ', f(y, 1000, ('bytes', 'KB', 'MB', 'GB', 'TB', 'PB' ), 2)
# Funziona anche con secondi, minuti e ore! ^__^ '' for x in range(5): y = 35*(10**x) print '%s s' % y print ' ', f(y, 60, ('s', 'm', 'h' ), 2) f_test() -- Wyrmskull _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python