To get the total disk space of a system in python, we can make use of the psutil
library which can be installed using pip.
Here's the code to get the total disk space in bytes:
main.py119 chars5 lines
The above code uses the disk_usage
method from the psutil
module by passing the file system path as '/'. This method returns a named tuple representing the disk usage statistics for the path. We then extract the total space using the total
attribute of the tuple.
This will output the total disk space in bytes. If you want to convert it to a different unit such as GB or TB, you can do so by dividing the total disk space with the corresponding unit-size in bytes.
gistlibby LogSnag