To move a CSV file from one location to another in Python, you can use the os
and shutil
modules.
The os
module provides a set of methods to interact with the file system, such as copying, moving, renaming, etc. The shutil
module builds on top of os
and provides some additional high-level file operations.
Here is an example code to move a CSV file using these modules:
main.py422 chars15 lines
In this code, we first specify the path of the CSV file we want to move and the destination directory we want to move it to. Then, we use shutil.move()
method to move the file to the destination directory. Alternatively, we can use os.rename()
method to achieve the same result.
Note that both methods can be used for any file type, not just CSV files.
gistlibby LogSnag