Partition names with Python
John Hunter
jdhunter at ace.bsd.uchicago.edu
Mon Jun 30 11:47:54 EDT 2003
>>>>> "Erhan" == Erhan Ekici <erhan at uzem.itu.edu.tr> writes:
Erhan> Hi, How do I get partition names (i.e. C:\ , D:\ ,E:\ on
Erhan> windows, hda,hda1 , hda2 on Linux machines) using Python.
There is nothing to do this in the standard library as far as I know,
but it is fairly easy to parse the output of fdisk. If you are
running as su
#!/your/path/to/python2.2
import os
for line in os.popen('/sbin/fdisk -l').readlines():
if line.find('/dev/') !=0: continue
columns = line.split()
print columns[0].split('/')[-1]
Should do it. With a little work, you could modify this to work cross
platform if you have fdisk installed on your win32 machine.
JDH
More information about the Python-list
mailing list