File system path annotations
Thomas Passin
list1 at tompassin.net
Mon Jun 19 11:23:00 EDT 2023
On 6/19/2023 10:04 AM, Roel Schroeven via Python-list wrote:
> Op 19/06/2023 om 11:44 schreef Peter Slížik:
>> Thank you, Roel. You've answered all my questions.
>>
>> > [PEP 519]: ...as that can be represented with typing.Union[str,
>> bytes, os.PathLike] easily enough and the hope is users
>> > will slowly gravitate to path objects only.
>>
>> I read a lot on Python and, frankly, I don't see this happening.
>> People on the Internet keep using /str/ as their path representation
>> choice. Presumably, programmers don't feel the need to bother with a
>> complex solution if the simplest option works just fine.
> I agree, I don't see that happening either. I often find myself using
> str for paths: often simple filenames are all that's needed, and then I
> don't see much point in importing pathlib and wrapping the filenames in
> Path() constructors. I do tend to switch to path objects when I start
> needing to do operations on the paths, though.
If you are writing code that will run on both Windows and Linux/Mac,
pathlib objects are very useful since the path separators will come out
right with no extra effort. Also, the syntax for composing a path seems
very natural (e.g., Path('a') / 'b' / 'c'), so that's a bonus.
More information about the Python-list
mailing list