format discs.

Gerhard Häring gh at ghaering.de
Wed Jul 9 17:42:12 EDT 2003


Taka wrote:
> On Wed, 09 Jul 2003 15:00:33 +0200, Gerhard Häring wrote:
>>Taka wrote:
>>>#!/bin/python
>>>
>>>import os
>>>partition = open ('/dev/hda1', 'w')
>>>
>>>for x in range(os.path.getsize('/dev/hda1'):
>>>	partition.write ('0')
>>>
>>>partition.close()
>> [...]
>>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