Created
October 17, 2012 17:33
-
-
Save shawnbutts/3906915 to your computer and use it in GitHub Desktop.
bytes to to mb, gb, etc in python
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 bytesto(bytes, to, bsize=1024): | |
"""convert bytes to megabytes, etc. | |
sample code: | |
print('mb= ' + str(bytesto(314575262000000, 'm'))) | |
sample output: | |
mb= 300002347.946 | |
""" | |
a = {'k' : 1, 'm': 2, 'g' : 3, 't' : 4, 'p' : 5, 'e' : 6 } | |
r = float(bytes) | |
for i in range(a[to]): | |
r = r / bsize | |
return(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks , very help full , need to change the bytes to days
1.4492465e+07 to day