[Tutor] creating a tab delimited filename

Max Noel maxnoel_fr at yahoo.fr
Tue Mar 15 05:20:48 CET 2005

On Mar 15, 2005, at 03:35, jrlen balane wrote:

> how am i going to change the filename automaticaly?
> for example:
>         #every 5 minutes, i am going to create a file based on the 
> data above
>  for i in range(100)
>         output_file = file('c:/output' +.join(i) +'.txt', 'w')
> #guess this won't work
>         output_file.writelines(lines)
>         output_file.close()

	I'm not going to give you a complete solution because that'd spoil the 
fun, but you need to use the os.path.exists function (in the os 
module), which tells you if a file exists or not (no need to open it -- 
actually, your loop is dangerous: opening a file with "w" as the mode 
erases it).
	As for generating the file name, you've almost got it. Just remove 
that bizarre call to "join", cause that won't work, and replace your 
for loop with a while loop, so that you can break out of it when you've 
found the correct file name, not before or after.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

More information about the Tutor mailing list