Get hard disk size in Python

前端 未结 4 1031
闹比i
闹比i 2020-12-23 20:01

I am trying to get the hard drive size and free space using Python (I am using Python 2.7 with macOS).

I am trying with os.statvfs(\'/\'), especially wi

4条回答
  •  悲哀的现实
    2020-12-23 20:46

    https://pypi.python.org/pypi/psutil

    import psutil
    
    obj_Disk = psutil.disk_usage('/')
    
    print (obj_Disk.total / (1024.0 ** 3))
    print (obj_Disk.used / (1024.0 ** 3))
    print (obj_Disk.free / (1024.0 ** 3))
    print (obj_Disk.percent)
    

提交回复
热议问题