Hi, I've found myself typing too many time this: pathlib.Path("some-dir-name").mkdir(parent=True, exist_ok=True) Wouldn't be better to have a pathlib.Path.makedirs with parent/exist_ok set to True by default? Thanks
On Wed, Jan 13, 2021, at 08:31, Antonio Cavallo wrote:
Hi, I've found myself typing too many time this: pathlib.Path("some-dir-name").mkdir(parent=True, exist_ok=True)
Wouldn't be better to have a pathlib.Path.makedirs with parent/exist_ok set to True by default?
Worth mentioning, that os.makedirs does not set exist_ok to True by default. I have been baffled by this decision, but not following it in pathlib would arguably be an inconsistency.
On 18Jan2021 16:49, Random832
On Wed, Jan 13, 2021, at 08:31, Antonio Cavallo wrote:
I've found myself typing too many time this: pathlib.Path("some-dir-name").mkdir(parent=True, exist_ok=True)
Wouldn't be better to have a pathlib.Path.makedirs with parent/exist_ok set to True by default?
Worth mentioning, that os.makedirs does not set exist_ok to True by default. I have been baffled by this decision, but not following it in pathlib would arguably be an inconsistency.
I fall into the other camp. I like exists_ok=False because it is safer
behaviour.
If I'm writing code which expects to make a directory, I _almost always_
want that directory to be _new_ and empty, unused by some other purpose.
If exists_ok were True by default it would be very easy to write code
which accidentally used a directory belonging to something else.
I would far rather such reuse required a little thought on my part, by
requiring specific calling out that exists_ok=True.
Cheers,
Cameron Simpson
participants (3)
-
Antonio Cavallo
-
Cameron Simpson
-
Random832