Script Generation, help!

John Doe atterdan at yahoo.com
Fri Nov 5 10:43:40 CET 2004


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




More information about the Python-list mailing list