[Tutor] file opening modes
David Rock
david at graniteweb.com
Wed Sep 10 12:51:00 EDT 2003
* Lloyd Kvam <pythontutor at venix.com> [2003-09-10 12:30]:
> 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
You need to determine if the file has already been opend by a different
process though (which one opens it "first")?
Another possibility would be to use os.tmpfile() or os.tempnam() to
create a random name temp file to write data to. This way you could
create as many as you wanted. The only disadvantage to os.tmpfile is the
file will be removed automatically when it is no longer needed.
os.tempnam just gives you a random name that you ca then use.
Another possibility is to generate names dynamically based on date.
--
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20030910/fd4d1347/attachment.bin
More information about the Tutor
mailing list