[Tutor] How to get file permissions (Python 2.4)?
Walter Prins
wprins at gmail.com
Wed Mar 19 18:46:25 CET 2014
Hi
On 19 March 2014 18:48, leam hall <leamhall at gmail.com> wrote:
> I can use os.chmod('/usr/local/somefile') to change permissions but I
> haven't been able to find a way to test for file modes.
>
>>>> stat.S_IRWXU('/usr/bin/python')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: 'int' object is not callable
>
> What should I be looking for? Python 2.4.3 (RHEL 5)
You're using the stat module as described here:
http://docs.python.org/2/library/stat.html
The constant stat.S_IRWXU is listed under a section that just to
defining the constant, reads:
"The following flags can also be used in the mode argument of os.chmod():"
Which means, that you can do, for something like:
>>> import os
>>> import stat
>>> os.chmod('/some/file/some/where', stat.S_IRWXU)
This has the effect of changing the file mode for the specified file
to "read, write, execute" for the user only and is the equivalent of
executing 'chmod u+rwx /some/file' or 'chmod 700 /some/file' from the
command line.
HTH,
Walter
More information about the Tutor
mailing list