我正在处理的代码抛出了错误Unsupported operand type(s) for +: 'WindowsPath' and 'str'
。我已经尝试了很多方法,但没有一个能解决这个问题(除了删除具有错误的行,但那并不有用)。
为了背景,这个脚本(完成后)应该:
- 基于您键入的ID在指定在SongsPath.txt中的目录中查找文件(mp3)
- 备份它
- 然后将其替换为另一个文件(以前一个文件的名称重命名)
以便获取这些文件的程序播放新歌曲而不是旧歌曲,但随时可以恢复到原始歌曲。(这些歌曲是从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")
print (sr.read())
Path()
不会返回一个字符串,它会返回一个Path
对象。 - Barmarpath sp
是复制错误吗?应该只是sp
吗? - Barmar