Created
August 24, 2024 17:18
-
-
Save Pymmdrza/c8918a425bd6cccf451e755134e4ebbe to your computer and use it in GitHub Desktop.
Natural File Size Convertor on Python
This file contains hidden or 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 naturalsize(num_bytes: int) -> str: | |
| for unit in ['B', 'KB', 'MB', 'GB', 'TB']: | |
| if num_bytes < 1024.0: | |
| return f"{num_bytes:.2f} {unit}" | |
| num_bytes /= 1024.0 | |
| return f"{num_bytes:.2f} PB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment