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
The code is about right, but you're using wrong fields, which may give you the wrong results on a different system. The correct way would be:
>>> os.system('df -k /')
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 14846608 3247272 10945876 23% /
>>> disk = os.statvfs('/')
>>> (disk.f_bavail * disk.f_frsize) / 1024
10945876L