[Tutor] Newbie question: join() string method
Alan Gauld
alan.gauld at btinternet.com
Mon Nov 27 19:46:04 CET 2006
"Moedeloos Overste" <kloosterjunkie at hotmail.com> wrote
> One question: When I run the program from IDLE it writes the data to
> file
> but when I run it from the command prompt(win32) it doesn't. why is
> this?
How do you know? Have you searched for the file?
Or are you looking in the same file that IDLE produced?
I would expect the code to create a new file in the current
directory - wherever you started the program. Did you look
there?
-----------------------
while vDraws > 0:
LotNumbers = random.sample(range(1,45), 6) #random numbers from
range
into list)
strgOutput=",".join(str(i) for i in LotNumbers)
#??????converting list
to string to store it.
fout = open("draw__output.dat", "a")
fout.write(strgOutput + "\n") #writing string to file
fout.close()
--------------------------
It's probably better to put the open/close outside the loop
fout = open(...,'w')
while vDraws > 0
...
fout.write(strgOutput + '\n')
vDraws -= 1
fout.close()
That way you can use 'w' to write the file(unless you really want the
previous runs to be in there too.) Also this will save the program
opening and closing the file for each line which is quite a slow
process.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list