[Discuss] File permissions in Python
Adam Parkin
pzelnip at telus.net
Sat Aug 5 12:58:37 PDT 2006
Deryk Barker wrote:
>> $x = "foobar.txt"
>> print "$x is: ", ((-R $x) ? "readable " : ""),
>> ((-W $x) ? "writeable " : ""),
>> ((-x $x) ? "executable\n" : "\n");
>
> The exact equivalent of what you're doing here would seem to be the
> os.access function.
>
> name = 'foobar.txt'
> print name, 'is',
> if os.access (name, os.R_OK):
> print 'readable',
> if os.access (name, os.W_OK):
> print 'writeable',
> if os.access (name, os.X_OK):
> print 'executable',
> print
Sweet, worked like a charm. Thanks! And yes, this Python code has the
same semantics as the Perl code (no output if no permissions set).
--
Adam Parkin
E-mail: pzelnip at telus.net
----------------------
Procrastination is the art of keeping up with yesterday.
More information about the Discuss
mailing list