Login
You're viewing the front-end.social public feed.
  • Sep 6, 2026, 10:07 PM

    I swear I just saw something today or yesterday about pathlib vs os.path for parameters.

    I have forever done something like:

    ```
    from os.path import isfile
    def read_file(file_path: str) -> None:
    if not isfile(file_path):
    print(f"{file_path} is not a file")
    return None
    ...

    ```

    Which is fine, and returning `None` from there all depends on what you want to happen; should it raise an Exception etc..

    So instead of `file_path: str` and passing a `pathlib.Path` or similar would be calling a method on the object itself instead of just calling `os.path.isfile` (or similar).

    What am I missing here? Am I trying to be too creative about something trivial?

    #python

    💬 0🔄 1⭐ 1