473,396 Members | 1,861 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,396 software developers and data experts.

Script Generation, help!


I'm new to python, so I'll be at detailed as I can be.

I need to generate a script where each line is like this:

Spam=(x)
Spam=(y)
Spam=(z)

each entry being on their own line, Spam is a string of text and
x,y,and z are random numbers, I also need it to be exported to a text
file with a specified extension.... being completely NEW to python I
push in the right direction would be really helpfull!

Thanks,
Pat


Jul 18 '05 #1
2 1019
A sketch of a solution could be (untested):

yourText = "%s=(%d)" % (yourString, yourNumber)
try:
f = open(yourFileName, "wt")
f.write(yourText + "\n")
f.close()
except IOError, e:
print "There's a problem writing to file %s: %s" % (yourFileName, e)

Creating strings and numbers and putting that and the write into a loop is
yours ;-)

Kind regards
Franz GEIGER

"digital_ant2" <di**********@yahoo.com> schrieb im Newsbeitrag
news:ma**************************************@pyth on.org...

I'm new to python, so I'll be at detailed as I can be.

I need to generate a script where each line is like this:

Spam=(x)
Spam=(y)
Spam=(z)

each entry being on their own line, Spam is a string of text and
x,y,and z are random numbers, I also need it to be exported to a text
file with a specified extension.... being completely NEW to python I
push in the right direction would be really helpfull!

Thanks,
Pat

Jul 18 '05 #2
Some times I think my question are cryptic.

text name = a number. Try a dictionary

myDict = {} # empty defination
myDict[Spam1] = 123939392
myDict[Spam2] = 439322
myDict[Spam3] = 23233.232

Now as to storage with an extension. Thats not so tricky, it's just
that your requirement is so vague.

To save the data myDict ...
import pickle
fp = open('myfile.myspecialext', 'w')
pickle.dump( myDict, fp )
fp.close()

To reload the data ...
import pickle
fp = open( 'myfile.myspecialext', 'r')
myDict = pickle.load( fp )

Now if you have some special format the data is stored in, you may want to
visit Parser. I've not had a chance to use it, but the description is
pretty neat.

Hope this is something like what you want.

On Fri, 05 Nov 2004 07:06:15 +0000, digital_ant2 wrote:

I'm new to python, so I'll be at detailed as I can be.

I need to generate a script where each line is like this:

Spam=(x)
Spam=(y)
Spam=(z)

each entry being on their own line, Spam is a string of text and
x,y,and z are random numbers, I also need it to be exported to a text
file with a specified extension.... being completely NEW to python I
push in the right direction would be really helpfull!

Thanks,
Pat


Jul 18 '05 #3

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

Similar topics

4
by: Munja | last post by:
I have PHP script running complex query and then calculating data for different conditions from received result set. Actually, it's doing the same as if I would make several queries with different...
51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
6
by: bissatch | last post by:
Hi, I am using the following code to generate images online: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta...
6
by: Brian | last post by:
Help.. We cannot get this script to work..can someone take a look at it and make suggestions? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Convert...
5
by: Praveen | last post by:
I have script files embedded as resources in my dll. During runtime, I would like to write it out into the app dir (or a app sub-dir) and send the appropriate virtual path to the client. This makes...
11
by: billmiami2 | last post by:
I recently generated a script using SQL Server 2005 for a local database that is configured as SQL Server 2000. Nevertheless, the script used the new structures and syntax (i.e., sys.objects vs....
0
by: Gawn | last post by:
Dear all, Greeding from Thailand. Need help for my news script. I am trying to display news which keywords match the current page keywords. I am using Dreamweaver 8 and PhpMyAdmin to manage MySQL....
0
by: Fantasys | last post by:
We're seeking undiscovered unappreciated genius. E-mail me at django@kentuckyescorts.net Fantasys Enterprises the leader the USA Escort Industry is seeking developers to form the core of...
4
by: J. Frank Parnell | last post by:
Hi there, I have a list of links which point to e.g. thescript.php?album=somePictures1 thescript.php?album=somePictures2 This list is about 3000 links. Each album may have 500 or more...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.