【Python】python取整函数和获取文件大小的方法

###Date: 2018.5.25

====================================================================

1、Python向上取整、向下取整和四舍五入取整函数

>>> import math
>>> math.ceil(12.5)
13.0
>>> math.floor(12.5)
12.0
>>> round(12.5)
13.0

2、获取文件大小:os.path.getsize()

'''获取文件的大小,结果保留两位小数,单位为MB'''
    def get_FileSize(filePath):
      filePath = unicode(filePath,'utf8')
      fsize = os.path.getsize(filePath)
      fsize = fsize/float(1024*1024)
      return round(fsize,2)


参考:

https://www.cnblogs.com/SZxiaochun/p/6961370.html

https://www.cnblogs.com/TTyb/p/6140867.html

https://www.cnblogs.com/shaosks/p/5614630.html

posted @ 2018-05-25 20:07  SoaringLee_fighting  阅读(794)  评论(0编辑  收藏  举报