I am trying to display partitions of linux using python and i want to do it using APIs. I have just tried the following code to get the output.
import os
f = os.popen ("df -h")
for i in f.readlines():
print "myresult : ", i
df command used for - report file system disk space usage
I think you required fdisk for Partition table manipulator for Linux.
you can use either os.popen or subprocess. just need root user login before running python script.
The folder /dev contains various devices. From these, devices named like sd[a-z]n (/dev/sda1, for instance) (on old machines with IDE drives hd[a-z]n), (where n-integer) are partitions. You can list using the file system access.
This has some limitations like unusual formatting of the whole drive as partition, but in general should work and also detect non-Linux partitions and with some luck USB sticks.