pathlib.Path.is_file vs os.path.isfile difference

Grant Edwards grant.b.edwards at gmail.com
Fri Mar 8 18:39:51 EST 2024


On 2024-03-08, Thomas Passin via Python-list <python-list at python.org> wrote:
>
>> Hi, I tested this with Python 3.8. Good to know that this was fixed!
>
> We just learned a few posts back that it might be specific to Linux; I 
> ran it on Windows.

On Linux, the limit is imposed by the filesystem.  Most of the "real"
filesystems on Linux have a 255 character limit, a few support 256,
and some of the legacy filesystems have lower limits. Reiser4 is the
only one that's even remotely common which supports more than 256 --
according to https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
it supports filenames up to 3976 bytes long.

NB: The behavior when the limit is exceeded might also vary from one
filesystem to another.

In any case, the pathlib docs for is_file() are explicit: any errors
from the underlying OS and libraries will be propogated. There is
nothing to fix.

 https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_file

  Path.is_file()

    Return True if the path points to a regular file (or a symbolic
    link pointing to a regular file), False if it points to another
    kind of file.

    False is also returned if the path doesn’t exist or is a broken
    symlink; other errors (such as permission errors) are propagated.


More information about the Python-list mailing list