On Sat, Jan 9, 2016 at 5:59 PM, Chris Angelico <rosuav@gmail.com> wrote:
On Sun, Jan 10, 2016 at 2:13 AM, Ram Rachum <ram@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@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/