473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Python script that generates blob files

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

Jul 18 '05 #1
4 2880
Sean Carey wrote:
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
Jul 18 '05 #2
"Sean Carey" <se********@gmail.com> writes:
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.
Jul 18 '05 #3
hey
thanks for the reply. I think I can make this work the way I need it
too.

Cheers

Sean

Jul 18 '05 #4
Sean Carey wrote:
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
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
13
by: Rolf Magnus | last post by:
Hi, I would like to embed a python interpreter within a program, but since that program would be able to automatically download scripts from the internet, I'd like to run those in a restricted...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
3
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around...
2
by: Kenneth McDonald | last post by:
I'm not trying to persuade my company to offer Python as a scripting language for their product, but I am trying to give them examples of things that Python can do easily that cannot be done easily...
2
by: fredniggle | last post by:
Hello, This is my first post here, and i'd like to thank you in advance for any help you can provide. While working on a python program to make HTML pages, i have encountered a problem when it...
4
by: Alia Khouri | last post by:
Can we open up the discussion here about how to improve setuptools which has become the de facto standard for distributing / installing python software. I've been playing around with ruby's gems...
1
by: Gabriel Genellina | last post by:
En Mon, 05 May 2008 19:43:24 -0300, David Anderson <zerty.david@gmail.com> escribió: ..class files map roughly to .pyc files Note that Python generates and writes .pyc files automatically when...
19
by: John Salerno | last post by:
Hey all. Just thought I'd ask a general question for my own interest. Every time I think of something I might do in Python, it usually involves creating a GUI interface, so I was wondering what kind...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.