Partition names with Python

John Hunter jdhunter at
Tue Jul 1 15:45:41 CEST 2003

>>>>> "Andrew" == Andrew Bennetts <andrew-pythonlist at> writes:

    Andrew> Or simply reading /etc/mtab or perhaps /proc/mounts (this
    Andrew> one is linux-specific, I think), rather than spawning a
    Andrew> process.

Good advice!  This seems to do it:

import os

for line in file('/etc/mtab'):
    if line.find('/dev/') !=0: continue
    columns = line.split()
    print columns[0].split('/')[-1]


More information about the Python-list mailing list