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:
question from:https://stackoverflow.com/questions/47518669/create-new-folder-in-python-with-pathlib-and-write-files-into-itFile "/Users/user/anaconda/lib/python3.6/pathlib.py", line 1164, in open opener=self._opener)
TypeError: an integer is required (got type str)