Creating a file with $SIZE
Chris
cwitts at gmail.com
Wed Mar 12 06:52:53 EDT 2008
On Mar 12, 12:32 pm, "k.i.n.g." <nkanthiki... at gmail.com> wrote:
> Hi All,
>
> I would like create files of different size, taking size as user
> input. I need to check the data transfer rates from one network to
> another . In order to do this I will have to create files of diff size
> and work out. I am new to Python
>
> Thanks in advance.
>
> KK
Welcome to Python.
If you just want to create files with random junk from the user input
then maybe something along these lines would help:
import sys, random
def random_junk(number_of_characters):
tmp = []
while number_of_characters:
tmp.append(random.randint(0, 127))
number_of_characters -= 1
return ''.join(map(str,tmp))
if len(sys.argv) < 2:
sys.exit('Usage:python %s <space seperated
filesizes>'%sys.argv[0])
for each_argv in sys.argv[1:]:
output_file = open(each_argv,'wb').write(random_junk(each_argv))
More information about the Python-list
mailing list