Why does pathlib not have is_readable() & things like that?

Grant Edwards grant.b.edwards at gmail.com
Thu Apr 28 09:34:31 EDT 2016


On 2016-04-28, Adam Funk <a24061 at ducksburg.com> wrote:
> On 2016-04-26, Random832 wrote:
>
>> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote:
>>> I recently discovered pathlib in the Python 3 standard library, & find
>>> it very useful, but I'm a bit surprised that it doesn't offer things
>>> like is_readable() and is_writable.  Is there a good reason for that?
>>
>> Well, one reason would be EAFP. Just try to open the file and see if it
>> gives you a PermissionError.
>
> I understand that in general, but the tool I'm working on here takes a
> command-line option to specify an output directory, & I'd rather not
> start processing the data (which involves GETting from a REST service,
> processing, and PUTting back modifications to the data) only to crash
> after the first batch because of a user error.

Then open the output file before you do the GET.

Or just do os.access("directory/where/you/want/to/open/a/file",os.W_OK)

-- 
Grant Edwards               grant.b.edwards        Yow! Jesus is my POSTMASTER
                                  at               GENERAL ...
                              gmail.com            




More information about the Python-list mailing list