[Python-ideas] More friendly access to chmod

Chris Angelico rosuav at gmail.com
Sat Jan 9 10:59:41 EST 2016


On Sun, Jan 10, 2016 at 2:13 AM, Ram Rachum <ram at rachum.com> wrote:
>
> What do you think about enabling a more friendly interface to chmod
> information in Python? I believe that currently if I want to get chmod
> information from a file, I need to do this:
>
> my_path.stat().st_mode & 0o777
>
> (I'm using `pathlib`.)
>
> (If there's a nicer way than this, please let me know.)

Have you looked at the 'stat' module? At very least, you can ask
questions like "Does group have execute permissions?" like this:

my_path.stat().st_mode & stat.S_IXGRP

You can also get a printable rwxrwxrwx with:

stat.filemode(my_path.stat().st_mode)

ChrisA


More information about the Python-ideas mailing list