This is a recipe that shows how to easily get disk partition information, in a cross-platform manner (for the supported OSes), from your computer's operating system, using the psutil library for Python.
1 2 3 4 5 6 7 8 9 10 | from __future__ import print_function
import psutil
dps = psutil.disk_partitions()
fmt_str = "{:<8} {:<7} {:<7}"
print(fmt_str.format("Drive", "Type", "Opts"))
# Only show a couple of different types of devices, for brevity.
for i in (0, 2):
dp = dps[i]
print(fmt_str.format(dp.device, dp.fstype, dp.opts))
|
The psutil module tries to hide differences between supported platforms to the extent possible, but shows them when it is needed. Major supported platforms include Linux, the BSDs and Windows, to some level each.
The output from the recipe:
Drive Type Opts
C:\ NTFS rw,fixed
E:\ CDFS ro,cdrom
shows information about two partitions/drives on the machine the recipe was run on - the primary hard disk partition (C:), and the CD-ROM drive (E:).
More information available here:
https://jugad2.blogspot.in/2016/12/using-psutil-to-get-disk-partition.html