Post #1065479
2026-04-08 18:08 UTC
Python Tip #98 (of 365):
Don't use open method on pathlib.Path objects 🧵
Instead of this:
with path.open() as file:
...
Prefer this:
with open(path) as file:
...
Since Python 3.6, pathlib.Path objects can be passed to the built-in open function.
pathlib.Path's open method is a relic from an earlier version of pathlib that wasn't yet fully embraced by Python's various path-handling features.
I recommend using Python's built-in open() function everywhere.
#Python #DailyPythonTip
Replies (0)
No replies.