【发布时间】:2020-04-23 11:32:23
【问题描述】:
我使用 pathlib 打开存在于不同目录中的文本文件,但出现此错误
TypeError:`"Unsupported operand type for +:'WindowsPath' and 'str'"
当我尝试像这样打开当前目录的乐谱文件夹中存在的搁置文件时。
from pathlib import *
import shelve
def read_shelve():
data_folder = Path("score")
file = data_folder / "myDB"
myDB = shelve.open(file)
return myDB
我做错了什么还是有其他方法可以做到这一点?
【问题讨论】:
-
显然
shelve.open尚未更新以支持基于__fspath__协议的输入路径。所以你必须手动传递os.fspath(file)而不是file。
标签: python windows shelve pathlib