我正在做这样的事情:
import pathlib
p = pathlib.Path("temp/").mkdir(parents=True, exist_ok=True)
with p.open("temp."+fn, "w", encoding ="utf-8") as f:
f.write(result)
错误消息:AttributeError:“NoneType”对象没有“打开”属性
显然,根据错误消息,mkdir
返回None
.
Jean-Francois Fabre 提出了这样的修正:
p = pathlib.Path("temp/")
p.mkdir(parents=True, exist_ok=True)
with p.open("temp."+fn, "w", encoding ="utf-8") as f:
...
这触发了一条新的错误消息:
文件“/Users/user/anaconda/lib/python3.6/pathlib.py”,第 1164 行,在 open opener=self._opener)
TypeError: an integer is required (got type str)