[Tutor] file opening modes
Lloyd Kvam
pythontutor at venix.com
Wed Sep 10 13:30:02 EDT 2003
Jimmy verma wrote:
>
> I know which filenames i will be creating dynamically so i dont want
> these files to be already present when i run the program again.
>
> I hope i am right with the append mode or should i choose some different
> mode.
(I'm surprised I haven't seen replies to this yet.)
One alternative would be to use mode w the first time and then mode a thereafter.
I believe it is simpler to simply delete the files at the beginning. This can be
done by:
import os
# assumes that your known filenames are in fnamelist
for fname in fnamelist:
os.remove(fname)
If the file names in the fname list refer to file in some other directory,
os.remove( os.path.join(r'c:\some_other_dir', fname))
(Code was simply typed in and not tested. it should be close to correct.)
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-443-6155
fax: 801-459-9582
More information about the Tutor
mailing list