[Python-ideas] More friendly access to chmod

Ram Rachum ram at rachum.com
Sat Jan 9 11:06:57 EST 2016


On Sat, Jan 9, 2016 at 5:59 PM, Chris Angelico <rosuav at gmail.com> wrote:

> 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)
>


Thanks for the reference. Personally I think that `my_path.stat().st_mode &
stat.S_IXGRP` is not human-readable enough. I'll work on a nicer API.
Probably this for the same action you described:

'x' in my_path.chmod()['g']




>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160109/3360258c/attachment.html>


More information about the Python-ideas mailing list