Python format size application (converting B to KB, MB, GB, TB)

前端 未结 15 1869
轮回少年
轮回少年 2021-02-01 16:13

I am trying to write an application to convert bytes to kb to mb to gb to tb. Here\'s what I have so far:

def size_format(b):
    if b < 1000:
              r         


        
15条回答
  •  甜味超标
    2021-02-01 16:55

    Rather than modifying your code, you can change the behaviour of division:

    from __future__ import division
    

    This provides "true" division over the "classic" style that Python 2.x uses. See PEP 238 - Changing the Division Operator for more details.

    This is now the default behaviour in Python 3.x

提交回复
热议问题