Get drives and partitions list (Linux)

cantabile cantabile.03 at wanadoo.fr
Tue Jun 14 00:26:23 CEST 2005


Hi, Peter
Thanks for the reply. I'll check popen().
But you said I should not rely on fdisk... Why ? And should I prefer
sfdisk ? Why ?


Peter Hansen wrote:
> cantabile wrote:
> 
>> Hi, I'd like to get drives and partitions (and their size too) with
>> python under Linux. So far, I thought of reading /proc/partitions but
>> maybe i could use fdsik also ?
>> How would I do that in python ?
> 
> 
> Somebody else posted a very similar question quite recently.  A Google
> Groups search would probably lead you to the answers pretty quickly.
> (Try "partition proc sfdisk" or something like that.)
> 
> My previous answer was to call sfdisk, using os.popen().  Others
> suggested reading /proc/partitions.  I doubt fdisk (if that's what you
> meant) is a good idea.
> 
> There is no pure Python solution, so far as I know, probably because
> there may not be any standardized way of finding this information.
> 
> -Peter



More information about the Python-list mailing list