format discs.

Gerhard Häring gh at
Wed Jul 9 23:42:12 CEST 2003

Taka wrote:
> On Wed, 09 Jul 2003 15:00:33 +0200, Gerhard Häring wrote:
>>Taka wrote:
>>>import os
>>>partition = open ('/dev/hda1', 'w')
>>>for x in range(os.path.getsize('/dev/hda1'):
>>>	partition.write ('0')
>> [...]
>>Your approach is hard to beat in inefficiency.
> Yes, but since file partitions are usualy bigger than your physical RAM,
> you cannot do
> import string
> partition.write (string.zfill('0', partition.getsize('/dev/hda10')-1)

Certainly there are good block sizes between 1 and the size of the 
partion, right? In my experience, the optimum is somewhere between 2 kb 
and 8 kb.

If I ever needed to overwrite a partition with zeros on Unix from within 
Python I'd most probably do something like:

import os
os.system("dd if=/dev/zero of=/dev/myblockdevice bs=8192")

-- Gerhard

More information about the Python-list mailing list