error on os.open API

Chris Angelico rosuav at gmail.com
Mon Apr 5 13:57:48 EDT 2021


On Tue, Apr 6, 2021 at 3:50 AM Rami Khaldi <khaldi.rami at gmail.com> wrote:
>
>  Hello,
>
> It seems that the os.open API cannot distinguish between a permission error
> and the fact that a directory cannot be opened like files.
> The following script reproduces the scenario (tested on Python 3.8.2
> (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on
> win32) :
>
>
>
> *import osos.system('mkdir someDirectory')open("someDirectory")*
>
>
> *Result:*
>
>
>
> *Traceback (most recent call last):  File "<stdin>", line 1, in
> <module>PermissionError: [Errno 13] Permission denied: 'someDirectory'*
>

Is this the actual code? You're not using os.open() here, you're using
the built-in open() function. But also, it IS possible to open
directories:

>>> os.open(".", os.O_RDONLY)
3

Maybe you don't have permission to open that directory?

ChrisA


More information about the Python-list mailing list