[Discuss] File permissions in Python
Adam Parkin
pzelnip at telus.net
Sat Aug 5 09:31:01 PDT 2006
Continuing in the questions for the Python gurus series of e-mails.... =8-p
I've been banging my head for a little bit trying to figure out a quick
and easy way to read a file's permissions inside of a Python script.
What I want to do is be able to tell the rwx permissions (ideally for
all groups). I have found the os.stat function, and it's ST_MODE field,
but this returns a decimal number for all permissions (not just rwx for
the three groups). I suppose I could figure out the permissions from
the number via some and'ing and or'ing, but is there not some easier way?
If it helps: what I'm working on is taking all of the exercise solutions
to the problems in the Learning Perl book and rewriting them in Python
to help learn the langauge. The chunk of code I'm stuck on right now is
this (in Perl):
$x = "foobar.txt"
print "$x is: ", ((-R $x) ? "readable " : ""),
((-W $x) ? "writeable " : ""),
((-x $x) ? "executable\n" : "\n");
Thanks in advance.
--
Adam Parkin
E-mail: pzelnip at telus.net
----------------------
If electricity comes from electrons, does morality come from morons?
More information about the Discuss
mailing list