pythonfile-rename

How to rename a file using Python


I want to change a.txt to b.kml.


Solution

  • Use os.rename:

    import os
    
    os.rename('a.txt', 'b.kml')
    

    Usage:

    os.rename('from.extension.whatever','to.another.extension')