To rename a file in Python, we can use the os
or shutil
modules. Here's an example using os.rename()
:
main.py184 chars11 lines
Alternatively, we can use shutil.move()
to accomplish the same thing:
main.py190 chars11 lines
Both methods work similarly, but shutil.move()
has additional capabilities such as copying files to a different location while renaming.
gistlibby LogSnag