I'm doing something like this:
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)
Error message: AttributeError: 'NoneType' object has no attribute 'open'
Obviously, based on the error message, mkdir
returns None
.
Jean-Francois Fabre suggested this correction:
p = pathlib.Path("temp/")
p.mkdir(parents=True, exist_ok=True)
with p.open("temp."+fn, "w", encoding ="utf-8") as f:
...
This triggered a new error message:
File "/Users/user/anaconda/lib/python3.6/pathlib.py", line 1164, in open
opener=self._opener)
TypeError: an integer is required (got type str)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…