Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
988 views
in Technique[技术] by (71.8m points)

typeerror - Moving a file from one location to another in Python. Getting a dst error

I'm trying to move a file from one folder to another using Python. I've tried using shutil, os.replace, os.rename but I'm getting the same error each time of TypeError: move() missing 1 required positional argument: 'dst' enter image description here

Here is a snippet of my code (made ambiguous to avoid displaying sensitive info):

import os
import shutil

filename = f"fileNamePlaceholder"
directory = f"originalFileLocation"
destination = f"newFileLocation"

shutil.move(f'"{directory}{filename}","{destination}"')

Pretty basic, but I get the TypeError: move() missing 1 required positional argument: 'dst' error each time. I've tried pasting the output into the command line, and it does work and moves the file, but when I try to run it directly, I get the error. I've also tried the os library to move the file, but the 'dst' error as well. This should be pretty basic but I just can't get it to work.

Note: I'm working on Windows 10, in a Linux Bash Shell.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

take care to your quotes, you have a single argument in your shutil.move():

you wrote: shutil.move(f'"{directory}{filename}","{destination}"')

should be shutil.move(f"{directory}{filename}",f"{destination}")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...