[Tutor] fix overwriting issue

Alan Gauld alan.gauld at yahoo.co.uk
Tue Feb 6 08:31:38 EST 2018


On 06/02/18 10:34, renukesh nk wrote:
> i am facing issue while writing files to a folder, where the files get
> overwrite if they have same file names , so any help me to  fix

That's just what happens, what did you expect to happen?
The same would be true id you saved a file from notepad,
if you used an existing name notepad would overwrite the
old file (albeit with a warning).

Are you trying to add extra information to the end of an
existing file? If so use the "a" mode when opening the
file instead of "w".

If the problem is accidentally typing inan existing name
then you can use the os module to test whether the file
exists before opening it and giving a warning if it does.

But until we know more about what you are trying to do
we can't really offer much more help. Also it helps if
you show us the code - at lest the bit that opens the
file.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list