【问题标题】:Moving a file from one location to another in Python. Getting a dst error在 Python 中将文件从一个位置移动到另一个位置。得到一个 dst 错误
【发布时间】:2021-04-13 06:22:46
【问题描述】:

我正在尝试使用 Python 将文件从一个文件夹移动到另一个文件夹。我试过使用shutil,os.replace,os.rename,但每次TypeError时我都会遇到相同的错误:move()缺少1个必需的位置参数:'dst' enter image description here

这是我的代码的一个 sn-p(为了避免显示敏感信息而变得模棱两可):

import os
import shutil

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

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

非常基本,但我每次都会收到 TypeError: move() missing 1 required positional argument: 'dst' 错误。我尝试将输出粘贴到命令行中,它确实可以工作并移动文件,但是当我尝试直接运行它时,我得到了错误。我也尝试过 os 库来移动文件,但也出现了“dst”错误。这应该是非常基本的,但我无法让它工作。

注意:我正在使用 Linux Bash Shell 中的 Windows 10。

【问题讨论】:

    标签: python typeerror shutil movefile


    【解决方案1】:

    注意你的引用,你的 shutil.move() 中有一个参数:

    你写道:shutil.move(f'"{directory}{filename}","{destination}"')

    应该是shutil.move(f"{directory}{filename}",f"{destination}")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 2019-03-21
      相关资源
      最近更新 更多