def approximate_size(size, a_kilobyte_is_1024_bytes=True):
size = float(size)<EOL>if size < <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>multiple = <NUM_LIT> if a_kilobyte_is_1024_bytes else <NUM_LIT:1000><EOL>for suffix in SUFFIXES[multiple]:<EOL><INDENT>size /= multiple<EOL>if size < multiple:<EOL><INDENT>return '<STR_LIT>'.format(size, suffix)<EOL><DEDENT><DEDENT>raise ValueError('<STR_LIT>')<EOL>
Humansize.py from Dive into Python3
Mark Pilgrim - http://www.diveintopython3.net/
Copyright (c) 2009, Mark Pilgrim, All rights reserved.

Convert a file size to human-readable form.
Keyword arguments:
size -- file size in bytes
a_kilobyte_is_1024_bytes -- if True (default), use multiples of 1024
if False, use multiples of 1000
Returns: string