move a file in python

To move a file in Python, you can use the shutil.move() function from the shutil module or the os.rename() function from the os module.

Here's an example using shutil.move():

main.py
import shutil

# specify the source file path
src_file = '/path/to/source/file.txt'

# specify the destination directory path
dest_dir = '/path/to/destination/'

# move the file from source to destination
shutil.move(src_file, dest_dir)
237 chars
11 lines

And here's an example using os.rename():

main.py
import os

# specify the source file path
src_file = '/path/to/source/file.txt'

# specify the destination file path
dest_file = '/path/to/destination/file.txt'

# move the file from source to destination
os.rename(src_file, dest_file)
236 chars
11 lines

Either function should work fine for moving files in Python. Just make sure to specify the correct source and destination paths for your specific use case.

gistlibby LogSnag