Python script that generates blob files

S

Sean Carey

I am wondering if anyone knows of a python script or any other script
that will generate random files with random sizes that I can specify.
Thanks

Sean
 
I

Irmen de Jong

Sean said:
I am wondering if anyone knows of a python script or any other script
that will generate random files with random sizes that I can specify.

define "random files".

If you're on Linux or similar, just use the dd utility?

Otherwise something like this (where the contents of the file
is left blank):

f=open("filename","wb")
f.seek( desiredsize-1 )
f.write('\0')
f.close()

--Irmen
 
P

Paul Rubin

Sean Carey said:
I am wondering if anyone knows of a python script or any other script
that will generate random files with random sizes that I can specify.

Python 2.4 should have an os.urandom function that gives you a random
character string of a size you specify. I'm not sure if that's what
you're asking.
 
S

Sean Carey

hey
thanks for the reply. I think I can make this work the way I need it
too.

Cheers

Sean
 
P

Peter L Hansen

Sean said:
I am wondering if anyone knows of a python script or any other script
that will generate random files with random sizes that I can specify.

Presumably using the random module would help?

length = random.randint(0, 1000)
filename = 'test'

f = open(filename, 'wb')
i = 0
while i < length:
f.write(chr(random.randint(0, 255)))
f.close()

Slight variations could simplify this... use getopt or optparse
to retrieve command line arguments if you want to specify different
filenames or length ranges etc.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,684
Latest member
sparada

Latest Threads

Top