Post #1821653
2026-04-29 01:08 UTC
Python Tip #118 (of 365):
Instead of argparse.FileType, use pathlib.Path
The argparse module's FileType is deprecated (as of Python 3.14).
It has known issues: no newline argument accepted, encourages not using a context manager, etc.
Instead of argparse.FileType you should use pathlib.Path.
Using "type=Path" will auto-convert given arguments to pathlib.Path objects.
That way all command-line-provided file paths will turn into pathlib.Path objects automatically!
#Python #DailyPythonTip
Replies (0)
No replies.