小编Moo*_*iss的帖子

+ 不支持的操作数类型:“WindowsPath”和“str”

我正在处理的代码抛出错误Unsupported operand type(s) for +: 'WindowsPath' and 'str'。我尝试了很多东西,但没有一个能解决这个问题(除了删除带有错误的行,但这没有帮助)。

对于上下文,此脚本(完成后)应该:

  1. 根据您输入的 ID 查找文件(mp3)(在 SongsPath.txt 中指定的目录中)
  2. 把它备份
  3. 然后用另一个文件替换它(重命名为前一个文件的名称)

以便获取这些文件的程序播放新歌曲而不是旧歌曲,但可以随时恢复到原始歌曲。(歌曲是从newgrounds下载并通过他们的newgrounds音频门户ID保存的)

我正在使用 Python 3.6.5

import os
import pathlib
from pathlib import Path

nspt = open ("NewSongsPath.txt", "rt")
nsp = Path (nspt.read())
spt = open("SongsPath.txt", "rt")
sp = (Path(spt.read()))
print("type the song ID:")
ID = input()
csp = str(path sp + "/" + ID + ".mp3") # this is the line throwing the error.
sr = open(csp , "rb")
sw = open(csp, "wb") …
Run Code Online (Sandbox Code Playgroud)

python file-handling operands

7
推荐指数
2
解决办法
9493
查看次数

标签 统计

file-handling ×1

operands ×1

python ×1