Last active
April 29, 2024 20:10
-
-
Save ElectroDrome/2cc0193d47555125dfbc0b34a4107b0a to your computer and use it in GitHub Desktop.
Python: Format a number of bytes into a human readable format (non looping solution)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_bytes(bytes, units=[' bytes','KB','MB','GB','TB', 'PB', 'EB']): | |
return str(bytes) + units[0] if bytes < 1024 else human_size(bytes>>10, units[1:]) if units[1:] else f'{bytes>>10}ZB' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment