more files

Gerhard Häring gh at ghaering.de
Sat May 31 09:06:43 EDT 2003


Darren Teo wrote:
> Hey how would i do this if i have to write a list of strings into a 
> "oldfile1" and deleting the "oldfile" before renaming the "oldfile1" to 
> the "oldfile" ...... i hope i am making sense here ..... thanks

For deleting and renaming files, check out the docs on the os module.

Ok, let's pretend I do not know how to delete or rename a file using 
Python. Let's also pretend I'm completely new to Pyhton and for some 
strange reason haven't browsed the list of modules, yet.

One possibility is to ask my close friend Google with the keywords 
"python delete file" and the 8th hit is titled "How to delete a file?". 
Looks good. It's a question asked on this list almost exactly a year 
ago. With answer.

So the answer is to use some function in the os module. Aha. So I check 
the os module to look if it has a function to rename files, too. Bingo! 
There is one.

Whoa! Now I've learnt that browsing the documentation of the modules in 
the standard library could be quite useful for future questions.

Honestly, you should try a little harder to find answers to such trivial 
questions yourself.

-- Gerhard





More information about the Python-list mailing list