Creating a file with $SIZE

Chris cwitts at
Wed Mar 12 11:52:53 CET 2008

On Mar 12, 12:32 pm, "k.i.n.g." <nkanthiki... at> 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

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