Python Forum
converting data sizes like: 4k, 32k, 4m, 16m, 1g, etc - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: converting data sizes like: 4k, 32k, 4m, 16m, 1g, etc (/thread-19793.html)



converting data sizes like: 4k, 32k, 4m, 16m, 1g, etc - Skaperen - Jul-15-2019

i'm getting a string with a data size expressed in it like "4k", "32k", "4m", "16m", "1g". is there a Python library function that will do the conversion and give me the size as an int? support for size expressions like "3.5k" would be a plus.

edit:

i do want higher scale suffixes, too, as well as no suffix simple conversion.

edit2:

suffixes should be powers of 1024.


RE: converting data sizes like: 4k, 32k, 4m, 16m, 1g, etc - Skaperen - Jul-16-2019

with no answer and being unable to find one, i implemented my own which you can see here.