This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients ThatXliner, steven.daprano
Date 2020-11-29.10:02:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606644153.24.0.162618145846.issue42497@roundup.psfhosted.org>
In-reply-to
Content
As a new feature, this could only go into 3.10, 3.9 is in feature freeze.

The requirements are unclear, it could mean any of:

- the file's *owner* has the execute bit set;

- the file's mode has any execute bit set;

- the *current user* has execute permission (regardless of whether they are the file owner, part of the file's group, or other);

- the file is an executable file (an app or exe) rather than a script that calls an executable file;

- the file is *not* on a file system that has disabled execution;

- if the file is double-clicked in a graphical shell, the file will run as a script or program (as opposed to merely open for reading);

etc.

So the concept of "is this file executable?" is more complex than it seems.

But you could start with getting the execute bit for the file's owner:


import pathlib
import stat
p = pathlib.Path('some file')
p.stat().st_mode & stat.S_IXUSR


or you could try this to find out whether the file *may* be executable for the current user:


os.access(p, os.X_OK)



but read the docs for some complications:

https://docs.python.org/3/library/os.html#os.access
History
Date User Action Args
2020-11-29 10:02:33steven.dapranosetrecipients: + steven.daprano, ThatXliner
2020-11-29 10:02:33steven.dapranosetmessageid: <1606644153.24.0.162618145846.issue42497@roundup.psfhosted.org>
2020-11-29 10:02:33steven.dapranolinkissue42497 messages
2020-11-29 10:02:33steven.dapranocreate